Page 1 of 1

SOLVED Image file size handling - cached images

Posted: Sat Jan 11, 2014 10:39 pm
by mikejones85
Hi all

Wondered if I can pose a quick question. We've recently seen a slight up tick in visitors to our website but this has resulted in some high usage with our web host who has now warned us and is requiring us to reduce our usage.

I've been reviewing page load times across our site ( and think the primary issue are the wide range of images we have (the website is effectively an e-commerce site hence the large number of pictures). Recently, I've been limited the size of the original images to try to improve this. However, in reviewing page load times I've noticed that when Opencart creates a temporary image of a different size e.g. for category images or basket images, the cached version is several times larger than the original image.

For instance, I created an original image 500 x 500 (a PNG file) which was 37.3KB large. When reviewing page load times, the cached version for the category wide view was a file of 290 x 290 and was 329.4KB large! When this applied to large number of images on the site this is putting a lot of pressure on the servers.

Our site is running on Joomla with Aceshop (as the Opencart plugin). Does this sound typical however and if not, any have any thoughts on how to limit the file size of the cached images?

Any thoughts most welcome - thanks in advance.



Re: Image file size handling - cached images

Posted: Sun Jan 12, 2014 1:17 am
by granddaddy
It is better to use jpg for normal photo images. Png's are more suitable for logos.
If you have no choice and must use png, you can look at your code to see if 'png compression' is being used. But there are reports that sometimes a png will still be larger than before. You would have to make the change and then test a few file uploads (clearing the image cache first).

If you do want to try it, look in file:
for the function
public function save($file, $quality = 90)

In that function, look for the line:
imagepng($this->image, $file, 0);

To turn on compression, remove the comma and zero so it becomes:
imagepng($this->image, $file);

But if the zero has already been removed it means you have a more recent version where this change was made in the default source. If that's the case, your only option will be to use jpg's.

Re: Image file size handling - cached images

Posted: Sun Jan 12, 2014 8:55 am
by mikejones85
Thanks very much for your thoughts.

I have no real special requirement to use PNGs - I'd started using them at the outset as I found the images were crisper than JPEGs but hadn't appreciated how big the image size issue might become, especially with the cached images (or indeed at that stage how many images we may have!).

I'll have a look for the code as you suggest. By way of a follow-up question, by using JPEGs would the creation of the cached files that Opencart creates have a limited file size by default (rather than creating the larger PNG files)? (Appreciating that the original JPEGs will typically be smaller than the PNGs anyway).

Re: Image file size handling - cached images

Posted: Sun Jan 12, 2014 10:12 am
by billynoah
pngs can be smaller in some cases depending on the complexity of the image. if you have photoshop you can use the "save for web" feature and get everything under 100k. thumbnails and such shouldn't be a problem.

you can also reduce the quality and use compression to get things smaller. regardless of your hosts restrictions it's still good practice to try to reduce the size of your images as much as possible for the sake of those viewing the site.

Re: Image file size handling - cached images

Posted: Sun Jan 12, 2014 7:00 pm
by Shark
I use something like: ... on_id=8684 (I had a free one, which I modificated myself, but can't remember where I found it, think it was this: Saves me about 50-80 Mb for 500 products.

Re: Image file size handling - cached images

Posted: Sun Jan 12, 2014 7:24 pm
by mikejones85
Thanks again for your thoughts - all very helpful.

All images are saved for web - I generally target 100k for the file size (using PNGs) - product images are typically 500 x 500 in size. The strange bit is that I think the original file sizes are ok, the issue is when they're being resized they seem to jump significantly in size (even when the resizing is creating smaller thumbnails!).

Thanks for the extension though Shark - that appears to tick the box. I'm going to make an effort to changing some of the worst offending product images to JPEGs (some of the cached images are over 1mb from an original image of 200kb) - if that doesn't work I'll see what impact that extension might have.

Thanks again!

Re: Image file size handling - cached images

Posted: Sun Jan 12, 2014 8:02 pm
by Shark
It's because opencart generates new images (by php gd-functions), which aren't optimized. I didn't try the paid version, let me know if it's any good. One problem I have with my own modification is that it sometime takes too long for an image to optimize which results in a blank image (can be very annoying). BTW I use this class in php:
smushit-php - a PHP client for Yahoo!'s web service
Tyler Hall <>

Re: Image file size handling - cached images

Posted: Mon Jan 13, 2014 12:06 am
by billynoah
@mikejones85 i'm not exactly sure what the problem is. I looked at your site and category images are around 32k. larger product images are still under 100k. where are these large images you were mentioning?

Re: Image file size handling - cached images

Posted: Mon Jan 13, 2014 12:54 am
by mikejones85
Hi Billy - thanks for your reply - I've been working all day to reduce the file sizes so suspect it's was fixed before you looked at them.

@Granddaddy post at the start of thread proved very useful - after making this tweak and clearing the cache the resized images were about a 1/10th of what they were previously (some were well over 2mb) to would recommend this fix to anyone having the same issue.