How to optimize all images? (reduce file size)

Hi All

For performance optimization I’m trying to reduce the file size of every image in our media database. Can you tell me how you would go ahead with that? I’ve found different approaches which I’ll list here. Any inputs appreciated.

Since it’s about 2’000 images I don’t think waiting for the 2.3 rollout will help much(due to the replacing images function). I surely will not replace these manually.

Which of the following approaches would you recommend?

  • moc/imageoptimizer
    https://www.neos.io/download-and-extend/packages/moc/moc-imageoptimizer.html
    Seemed good until I read this is for “thumbnails”. Where / how is Neos generating thumbnails? I want every picture optimized.

  • Cronjob for jpegoptim & optipng
    I’ve ran these tools over the /Data/Persistent/Resources folder on our dev system. It reduced the folder size massively´ (~50%). Problems here are, in the neos database the attribute for file size is wrong (can I update the database somehow, to re-read the file attributes?) and when I asked in slack someone said these names are generated by attributes like file size. Do you guys see any problems with this approach?

  • Kraken.io
    Someone here implemented this somehow to their neos site? If yes, I will read more about it.

  • your solution?

Hey Severin,
I would recommend the moc/imageoptimizer solution. It optimizes all resized / cropped images Neos generates while leaving the originals untouched.

Cheers,
Daniel

2 Likes

Hi Severin,

Gotta agree with Daniel here (even if somehow biased) :thumbsup:

It is not done to all files, exactly to avoid interfering with the original files in case they are used for download the original e.g. Additionally jpegoptim has a problem with optimizing files again and again, resulting in degrading quality. See https://github.com/mocdk/MOC.ImageOptimizer/issues/2 for details.

Also AFAIR there will always be a thumbnail created if you use the image view helper, even though it could potentially be unnecessary.

Regarding the filesize, the MOC.ImageOptimizer has the same potential issue, however it’s never caused any problems to my knowledge.
Can also say that the filesize is not used to calculate the resource sha1, it’s simply using PHP’s sha1_file which is only based on the filename/path.

Haven’t heard of anyone using kraken.io with Neos, but if you have the possibility to use MOC.ImageOptimizer or do it yourself, it’s definitely cheaper.

Cheers,
Aske

Hi guys

Thanks for your inputs, I appreciate that.

Do you have an idea how to limit image uploads to the media database? I’d like to have file size and width of the different image types limited to a maximum of 2mb / 2560px.

Do you know if moc/ImageOptimizer ist just optimizing resized / cropped
images? Or is Aske right by saying as soon as the ImageViewHelper is
used, a thumbnail is generated? Will this thumbnail then be rendered
(and preferably optimized by the moc/ImageOptimizer?

Thanks for any efforts

Cheers, Sevi

There’s no built in way to limit image upload by such factores, you’d have to hook in somewhere and add that custom logic. You’d probably need to use AOP as I doubt it would be possible using configuration or signals.

You can test it by simply inserting an image with the view helper and don’t set any conditions and see if it’s the original image or a thumbnail…