funbox / optimizt

CLI image optimization tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

It works incorrectly

NovalnetLLC opened this issue · comments

Folder have 2 files for test:
banner-img-joy-smile-desctop.jpg
banner-img-joy-smile-desctop-ok.jpg

Call:
$ find . -iname *.jpg -exec optimizt --webp --avif {} +
ℹ Converting 2 images (lossy)...
✔ banner-img-joy-smile-desctop-ok.avif
100.776 KB → 50.825 KB. Ratio: 50%
✔ banner-img-joy-smile-desctop.avif
487.15 KB → 54.317 KB. Ratio: 89%
✔ banner-img-joy-smile-desctop.webp
487.15 KB → 127.719 KB. Ratio: 74%

ℹ Yay! You saved 826.768 KB (70%)

Result 3 files:
banner-img-joy-smile-desctop.avif
banner-img-joy-smile-desctop.webp
banner-img-joy-smile-desctop-ok.avif
banner-img-joy-smile-desctop-ok.webp - is not created


$ optimizt --webp /Images_Site/Home/test2/banner-img-joy-smile-desctop-ok.jpg
ℹ Converting 1 image (lossy)...
ℹ Done!
File banner-img-joy-smile-desctop-ok.webp - is not created

Please, attach the images as a ZIP archive to make it possible to reproduce the issue :-)

Now we can't help because we do not have the images.

Cool, thanks.

It happens because banner-img-joy-smile-desctop-ok.jpg's Webp version is bigger than the original JPEG. By default Optimizt does not create new files if they are bigger than their originals, because it does not look like optimization.

That's why you get this:

$ optimizt --webp --avif .
ℹ Converting 2 images (lossy)...
✔ banner-img-joy-smile-desctop-ok.avif
   100.776 KB → 44.247 KB. Ratio: 56%
✔ banner-img-joy-smile-desctop.avif
   487.15 KB → 49.084 KB. Ratio: 90%
✔ banner-img-joy-smile-desctop.webp
   487.15 KB → 127.719 KB. Ratio: 74%

ℹ Yay! You saved 838.579 KB (71%)

But if you want to get AVIF or/and Webp files always regardless of the optimization result, then use --force flag:

$ optimizt --webp --avif --force .
ℹ Converting 2 images (lossy)...
✔ banner-img-joy-smile-desctop-ok.avif
   100.776 KB → 44.247 KB. Ratio: 56%
✔ banner-img-joy-smile-desctop-ok.webp
   100.776 KB → 116.225 KB. Ratio: -15%
✔ banner-img-joy-smile-desctop.avif
   487.15 KB → 49.084 KB. Ratio: 90%
✔ banner-img-joy-smile-desctop.webp
   487.15 KB → 127.719 KB. Ratio: 74%

ℹ Yay! You saved 838.579 KB (71%)

As you see, created Webp version is 15% bigger than the JPEG. But it's still created because of --force flag use.

Ok, thanks. How can I specify for WebP optimization quality? For example: quality 50

It is not possible for now. Optimizt sets quality to 85 for JPEG/PNG → WEBP:

https://github.com/funbox/optimizt/blob/master/lib/convert.js#L204

We will think about adding this feature in the future though 🤔

Also PRs are always welcome 🐨