Sometimes clients upload large images to use on their site. Often you can just use an image optimization tool like phpThumb or pThumb to resize the images for the frontend.

But if you have lots of huge images on your site to optimize, your server may run out of resources, and even the manager wont be able of handling images larger than 4000px, and will not create thumbnails for such images. You don't need images with 6000px width or 300dpi on the web, so those need to be optimized.

Most of my clients are agencies and often upload images like that directly from the photographer. So I was looking for a good solution to optimize these images automatically on upload.

I found the Service of ImageOptim and built an extra for it. Whenever you upload an image, it will optimize the image automatically.

By default the extra just optimizes the images, but you can configure it to resize and crop as well with the system settings. For example, you can set a maximum width of 3000px or crop images to 200x200px.

By setting the maximum width to 3000px, I changed the size from 30 MB to 350 KB without any visible quality reduction.

There are a lot of other settings you can use, listed in the API documentation.

Filename extras

If you are using extras to manipulate the filenames on upload (such as fileSluggy). Make sure that the plugin priority for "OnFileManagerUpload" is set at a higher number than the priority of the imageOptimOnUpload plugin.

Contribute

ImageOptimOnUpload is on Github, where you can open issues if you have any problems or you can contribute by opening a pull request.

Check it out!

ImageOptimOnUpload can be downloaded from MODX.