optimized PNGs 5X larger than originals

I have mostly found the answer to my questions.

WordPress utilizes the GD Library or IMagick (ImageMagick by John Cristy) to create various sized thumbnails whenever a image is uploaded to the WP Media Library. Depending upon your theme, what you have in WP Dashboard/Settings/Media, and what plugins you have, you may get anywhere from 5 to 25 additional sized thumbnails (see screen shot of FTP directory in my post above).

Why were my optimized, original, 8-bit PNG files quadrupling in size for a smaller thumbnail?

It turns out that resizing and resampling PNGs is not ImageMagicks stong suit. A fantastic explanation is found here (even thought the article is dated and the solution in it no longer works): https://www.smashingmagazine.com/2015/06/efficient-image-resizing-with-imagemagick/

I also read in ImageMagicks forums that basically what is happening with the ImageMagick ‘-resize’ command is a 8-bit PNG gets converted to a 24-bit PNG to be resized – thus making it a larger filesize.

ImageMagick is part of the problem, but it’s also is the solution in my case.

From WordPress 5.8 on, webp is supported by default, and the thumbnails created by WP (ImageMagick) from a uploaded webp are smaller in bytes than the original, not quadruple the size (see screen capture).

screen capture of ftp directory

But how to best convert 50,000 PNG files to webP?

Yes, I considered offloading or on the fly image optimizations with a plugin like PicPerf.io, Smush, Imagify, TinyPNG… but for 50,000 images (+ thumbnails) this can get costly. Some solutions meant that both PNGs and (created) Webp images would reside in my uploads directory. That would mean that those original 50,000 images, multiplied by however many thumbnails WP creates upon upload, would get DOUBLED. Server space issue. Possible database show downs.

Ultimately, none of those plugins solve the problem of WP creating larger byte size thumbnails of the originally uploaded PNG files.

So after learning the basics of ImageMagick on the command line, and reading forums, I came up with this:

  1. Change directory to the directory of images

    cd ~/Path/to/images/folder

  2. Recursively find and convert all PNG images in that directory to webP:

    find . -type f -regex “.*.(jpg|jpeg|png)” -exec mogrify -format webp {} ; -print

  3. Once satisfied with the results, delete the PNG files:

    find . -type f -regex “.*.(jpg|jpeg|png)” -exec rm {} ; -print

Three commands and I can convert 50,000 PNGs (or Jpegs) to webp images, and since it is from the command line, it’s fast. And free.

In my case, the webps made from the command above were about 25-35% smaller than the PNG files. But my PNG files were already optimized by Adobe Illustrator (ImageReady engine) into relatively small 8-bit PNG files. Others may see larger size savings than that.

techhipbettruvabetnorabahisbahis forumuedusedusedueduseduedusedusedueduedu