2
votes

I've optimized an image that is 1280px x 800px in width/height and is 150kb in file size. I have used add_image_size to Wordpress to make different thumbnail, small and large versions of the uploaded image. However, when Wordpress sizes this image, it's much bigger in file size despite being smaller! I get this:

/* I only specified widths because the images keep the same ratio */ 

IMAGE NAME      WIDTH       FILE SIZE
--------------  -------     ----------
my-small-size   480px       112kb
my-medium-size  768px       211kb
my-large-size   1280px      150kb (I uploaded this version)

I have installed imagick, but don't know if Wordpress is using it. Is there a way to improve the compression that Wordpress uses?

EDIT: These are png images.

2
There are a lot of plugins that do that already.jeroen
have you tried wp-smush.it ?AhmadAssaf
@jeroen no there aren't. I looked at all the plugns I could find and all of them let you specify either a size for "small", "medium" and "large" but not your custom image sizes, or they only shrink jpegs. None of them seem to allow compression on PNGs for all the custom image sizes.Don Rhummy
Are you sure? This looks promising for example: premium.wpmudev.org/blog/…jeroen
@AhmadAssaf I don't want to install a plugin that relies on connection to another company's site. a good suggestion nonetheless.Don Rhummy

2 Answers

1
votes

The default quality when saving in WordPress is 90%.

If you want to change this, stick the following code in your functions.php for your theme:

function reduce_wp_image_quality( $quality ) {
  return 60; // default is 90% quality
}
add_filter('wp_editor_set_quality', 'reduce_wp_image_quality');
add_filter('jpeg_quality', 'reduce_wp_image_quality');

This should affect all thumbnails generated by WordPress.

--

wp_editor_set_quality is located in:

  • wp-includes/class-wp-image-edito.php:228

jpeg_quality is located in:

  • wp-includes/class-wp-image-edito.php:241
  • wp-admin/includes/image-edit.php:319
0
votes

Use JPEG images, that compress well. PNG will not help with compressing size when reducing the dimensions.