Are my blog images too heavy? I reduced the file sizes of three thumbnails. — cover illustration

Are my blog images too heavy? I reduced the file sizes of three thumbnails.


Do what you can first.

Convert 3 images to WebP using Node.js and sharp. In this PNG manuscript, the total size was 7.19MB, but it was reduced to approximately 0.21MB.

For those who want to reduce the size of images for blogs on Mac. You can reproduce it using the practice images distributed. The compression rate varies depending on the content of the image.

Table of contents of this article

After adding thumbnails, selecting articles became a little more fun. However, now that the image is complete, there is one more thing that concerns me.

Is it really OK to upload this file as it is?

This time, I resized three source thumbnail images for Ryu's Lab and converted them to WebP.Total 7.19MB reduced to approximately 0.21MB.I also made it possible to check the appearance side by side.

This is a verification performed during the editing process on November 5, 2026. The target is 3 AI-generated pen drawing PNGs. This is not a comparison of photos in general. Runs on Mac/Node.js v26.5.0/sharp 0.34.5. Unlike the actual thumbnail cropping to 1200 x 630, this comparison preserves the aspect ratio and makes it 1200 x 632. We do not measure actual page load time.

First, check the image file sizes.

This time, each PNG was approximately 2.3 to 2.5MB. Approximately 7.19MB for 3 sheets. Since the image will be used as the entrance to the article, consider whether it is necessary to send it in the original size.

For this test, I capped the width at 1200px and set WebP quality to 85. These are the settings I chose for this example, not necessarily the best settings for every image.

When I converted it, this is what happened.

  • a-place-for-curiosity.png:2,344,974 → 69,466 bytes
  • joy-of-choosing-gadgets.png:2,298,834 → 52,122 bytes
  • making-everyday-interesting.png:2,543,487 → 87,014 bytes

The total file size was reduced by approximately 97.1%. This is the result of width reduction and lossy compression to WebP.

Pen drawing PNG before conversion
Before conversion. This is the PNG that was actually used for conversion.
WebP converted with width 1200px and quality setting 85
After conversion. You can compare with the same display width as above. It is easier to judge thin lines and paper textures by enlarging them and comparing them.

It feels good to have less space, but fine lines are also important for images. The acceptable limit is determined by the actual display size.

From here, let's work together.

These instructions are for Mac. Copy only the “Command to run” blocks and press Enter after each command. Do not type the result blocks. The % and $ symbols at the start of a terminal line are prompts, so they are not included in the commands here.

1. Download practice files

Download practice ZIP

  1. Click the link and save. Normally, go to "Downloads" in Finder.
  2. Double-click the ZIP to extract it. If your browser is already expanded, use that folder.
  3. Open the folder and locate resize.mjs and input. You are ready when both are in the same folder.

There is no problem even if the folder name is something like "image-kit 2". In the next step, specify the actual folder by dragging it.

2. Open a terminal and move to where you want to work

  1. Press ⌘+Space, type "Terminal" and press Enter.
  2. Type cd in Terminal, with one space after cd. Do not press Enter yet.
  3. From Finder, drag the folder itself containing resize.mjs into Terminal.
  4. Press Enter when the folder location is entered.

You will see something like cd /Users/自分の名前/Downloads/image-kit. This is an example, not a path to copy. Changing directories successfully usually produces no message.

Command to run

pwd

Example of results displayed

/Users/自分の名前/Downloads/image-kit

Your current location will be displayed. You can use the name and save location of your own environment.

Command to run

ls -1

Example of results displayed

input
resize.mjs

If you see both resize.mjs and input, proceed to the next step. If you can't see it, select the folder again in step 2. The order and presence of other files does not matter.

3. Check Node.js for converting images

Node.js is software for running this JavaScript program. npm is a tool for adding parts used by programs.

Command to run

node --version

Example of results displayed

v26.5.0

If you get a version that starts with v, you can call Node.js. This is a confirmation environment display and does not need to have the same ending numbers.

Command to run

npm --version

Example of results displayed

11.17.0

npm can also be called if a number appears. The execution environment this time is Node.js 26.5.0.

command not found/Node.js is not installed
  1. Open Node.js official download page and choose the LTS macOS installer (.pkg) compatible with your Mac.
  2. Open the downloaded .pkg, check the displayed instructions, and install.
  3. Close the terminal, reopen it, and start over from moving the folder in step 2.
  4. Run node --version and npm --version again. Continue once both display a version number.

The instructions for installing the installer are based on official instructions. This time, we have not verified the UI operation itself for a new installation.

4. Add image conversion parts to the working folder

First create the configuration file. The -y option accepts the defaults instead of asking you to fill in each setting.

Command to run

npm init -y

Example of results displayed

Wrote to .../package.json:
{
  "name": "image-kit",
  ...
}

If you see a message that package.json has been written, it is a success. This is an excerpt of the output, and the folder name will change depending on your environment.

Next, install sharp, the library that converts the images. This step requires an internet connection.

Command to run

npm install [email protected]

Example of results displayed

added ... packages ...

When a message such as added appears and the screen returns to waiting for input, confirm with the following command. Information on the number of cases, required time, funding, etc. will change. If it stops with a red error, you cannot proceed.

Command to run

npm ls sharp

Example of results displayed

[email protected] .../image-kit
└── [email protected]

If you can see [email protected], it has been installed. Up to this point, node_modules, package.json, and package-lock.json have increased.

5. convert images

input is the source folder and output is the destination. The script keeps input unchanged and creates separate files in output.

Command to run

node resize.mjs input output

Execution results for this practice image

[
  {
    "file": "a-place-for-curiosity.png",
    "before": 2344974,
    "after": 69466,
    "width": 1200,
    "height": 632
  },
  {
    "file": "joy-of-choosing-gadgets.png",
    "before": 2298834,
    "after": 52122,
    "width": 1200,
    "height": 632
  },
  {
    "file": "making-everyday-interesting.png",
    "before": 2543487,
    "after": 87014,
    "width": 1200,
    "height": 632
  }
]

If there are 3 results, it is a success. before is the number of bytes before conversion, and after is the number of bytes after conversion. width and height are the number of pixels after conversion. The capacity may vary slightly depending on the OS, etc., but please also check the output and dimensions of the three sheets.

6. Open the created file

Command to run

ls -1 output

Example of results displayed

a-place-for-curiosity.png.webp
joy-of-choosing-gadgets.png.webp
making-everyday-interesting.png.webp

If you can see the three files, you can also check the save destination. .png.webp is the name this script gave, leaving the original file name.

Command to run

open output

Example of results displayed

(ターミナルには通常、何も表示されません)

The output folder will open in Finder. Select an image and press the space key to check it with Quick Look. Please open the input of the original image and compare the lines and colors.

The practice is now complete.If all three WebP images have been created and open in Finder, the practice worked. Continue only if you also want to try your own images.

7. Try it with your own images (advanced)

Command to run

mkdir my-input

Example of results displayed

(何も表示されません)

You now have a folder to put your images into. If a folder with the same name already exists, use that folder or rename it.

Command to run

open my-input

Example of results displayed

(Finderでmy-inputが開きます)

Select the original PNG or JPEG in Finder and press ⌘C, then ⌘V in my-input to copy it. Please leave the original image separately.

Command to run

node resize.mjs my-input my-output

Example of results displayed

[
  { "file": "自分の画像.png", "before": ..., "after": ..., "width": ..., "height": ... }
]

This is an example of displaying only the structure. It is a success if file becomes your image name and WebP is created in my-output.

This script processes still PNG and JPEG images directly inside the input folder. It does not process HEIC files, animations or images in subfolders, and it does not send images to an external service.

When it stops, check here

  • Cannot find module ...resize.mjs: You may be in the wrong folder. Use ls -1 from step 2 to check the files.
  • Cannot find package 'sharp': Run npm install [email protected] from step 4 in the folder containing resize.mjs.
  • ENOENT ... input: The input folder name is incorrect. Check it with ls -1.
  • If the only output is [], there may be no matching PNG or JPEG files. Check with ls -1 input.
  • EEXIST: The previous output remains. Since the specification does not overwrite, change the output destination as follows.

Command to run

node resize.mjs input output-2

Example of results displayed

[
  { "file": "a-place-for-curiosity.png", ... },
  ...
]

If you can save a new file to output-2, the re-execution is successful. If output-2 also exists, give it an unused name such as output-3. This is an excerpt of the results.

Empty files may remain in the output destination where the process fails. The input image is unchanged, so start over with the new output destination.

For those who want to see the contents of the distribution code

See the executed code
import fs from 'node:fs/promises';
import path from 'node:path';
import sharp from 'sharp';
const input = process.argv[2] ?? 'input';
const output = process.argv[3] ?? 'output';
if (path.resolve(input) === path.resolve(output)) throw Error('入力と出力は別のフォルダにしてください');
await fs.mkdir(output, {recursive:true});
const results=[];
for (const entry of await fs.readdir(input, {withFileTypes:true})) {
  if (!entry.isFile() || !/\.(png|jpe?g)$/i.test(entry.name)) continue;
  const source=path.join(input,entry.name);
  const target=path.join(output,entry.name+'.webp');
  // wx prevents overwriting an existing output file.
  const handle=await fs.open(target,'wx');
  try {
    const buffer=await sharp(source).rotate().resize({width:1200,withoutEnlargement:true}).webp({quality:85}).toBuffer();
    await handle.writeFile(buffer);
    const meta=await sharp(buffer).metadata();
    results.push({file:entry.name,before:(await fs.stat(source)).size,after:buffer.length,width:meta.width,height:meta.height});
  } finally {await handle.close();}
}
console.log(JSON.stringify(results,null,2));

From the next image, please take a moment before posting it.

Rather than performing difficult optimization every time, first consider the display size and check the capacity and appearance. With this extra effort, you can easily incorporate it into the process of writing articles.

Just converting to WebP won't necessarily make your site faster. This time, I will record my progress up to the point where I was able to make the image file itself smaller.

If you are also interested in making the images, read Articles about the joy of creating. I will keep sharing ways to turn what I learn into something useful.

References: sharp resize documentation and WebP output specifications. I checked the API requirements and measured the file sizes above locally.

How to have published articles found through search

After reducing image file sizes, check whether Google has indexed the article. Records of SEO measures implemented on personal blogs walks through titles, internal links and analytics using Search Console.