Mikael Högbergs blog

Main menu

Post navigation

Sitecore Image Optimizer module

This is going to be a very short one – I’m really too busy right now to spend time on doing a proper blog post. I hope I’ll manage to do an update soon.

I’ve just spent two hours creating an image optimization module that’s just submitted to Sitecore Marketplace. It will run pngcrush, jpegtran, or whatever image compression utility you prefer on your images in media library.
Since I shouldn’t redistribute pngcrush/jpegtran, you’d have to download those two exe files yourself and put them in a suitable location on your server. Just update the config file with the location of those files and you may also fiddle with the command line arguments to suit your needs.

Once installed, a Compress menu option will appear in the media ribbon. It will only be active for png and jpg images. Clicking compress will start the compression job.

The original file will be backed up into your configured backup folder. On a successful compression, i.e. the resulting file is smaller; the new file will be attached to the media item.
In the future, I’d like to do the same processing for resized images as well.

Using this tool, the Android simulator background image that comes with a clean Sitecore setup, was shrinked from 112278 to 71138 bytes. That’s a reduction of almost 37% without any loss in image quality.

Thank’s for the notify! Stupid me forgot to hit the publish button in Sitecore marketplace. It’s up for review now, so it’ll be there any time. (It’s really simple at this stage and I hope I get the time to do an improved version.)

Nevermind. I figured it all out. Works great. Number 1 feature request would be support running it over an entire folder. Number 2 would be to keep the popup visible to see the savings as it disappears for me in Chrome.

Sorry, I’m still having issues. Although I can see in the Sitecore backend that the media item says it is smaller, when I browse to that image via url and save that image it is still the original. Could this be a media cache thing?

It seems like the backup is created, the temporary image optimised is created but on replacement of existing media item image it updates the file but with the same image resulting image size. Timestamp is updated, size of image in the sitecore UI is updated, but image size is still original.

Do you have an open source version of this anywhere that I can look at and submit a pull request? Seems like an issue with media.SetStream(newStream, extension); I am using filesystem media storage and running Sitecore v7. Thanks.

That is funny. I made almost the same small module 2 weeks ago, hadn’t noticed yours on market place. Mine is just as primitive maybe even a bit more, it was coded in less than 2 hours but it looks kind-of similar, see http://laubplusco.net/crush-png-in-sitecore/

When you take poladroid images they first appear scattered/movable over the desktop, ..i like this effect, but whenever you close the package/shut down, the iamges are saved to ‘my images’ as normal files. Is there a way to review the photos scattered over the desktop again?

Our OpenEXR codec produces highest quality 64bpp RGBA floating point data (16 bits per components, with Alpha) and support many variants of the EXR format, including tiled images and several compression schemes. The codec reads all sample images supplied by ILM with the OpenEXR SDK. The codec uses processor-specific optimizations to speedup unpacking of zip-compressed EXR files. The current version also supports multi-resolution files and can extract lower resolution mipmap levels directly, through the IWICBitmapSourceTransform interface.

Thank you very much for this module! I have added some functionalities in your module. I have change the the compressor for png by pngquant wich is clearly more performant now. And I have added a wizard to compress a complete folder with or without the sub-folder. This wizard is optimized to not re-compress the already compress images.

So is it ok for you if I release an updated version of this module? I will definitively put your blog and your original module in the references of course.

Sure, no problem. I’m happy you found this simple module useful and could add more functions to it! My intention was to do something similar, but never had the time to fulfil it. One thing that’s still on my todo-list is adding the compressor as plugin into the media stream, so that images that are resized runtime on CD-servers get compressed as well. (See my old blog post on large scale web apps)