0

When image uploaded to the wp gallery - thumbnails automatically created, in my case 294x294, 191x191, 99x99 - these thumbnails are generated at very high compression / low quality.

In order to improve the appearance of the products in my shop and to add some product description to the thumbnails, I Photoshopped my own set of 294x294, 191x191, 99x99 images and uploaded them directly to the server via ftp replacing automatically generated thumbnails.

But for some reason over time my thumbnails get replaced with automatically generated images again and again, probably due to some size threshold.

WP generated thumbnail, 7.5kb :

WP generated thumbnail

Required thumbnail, 14kb :

enter image description here

What script does automatic regeneration of already existing thumbnails and is there any way to disable it?

  • There are multiple extensions meant precisely for force regeneration of image sizes, so it's both unlikely that WP core does it and hard to guess which one might be responsible in your case. – Rarst Jan 8 '14 at 20:43
  • Ok, not the best practice in the world but in order to prevent existing files from being rewritten i've file permissions set to 444. This action immediately caused record in error log: [09-Jan-2014 05:19:20 UTC] PHP Warning: imagejpeg() [<a href='function.imagejpeg'>function.imagejpeg</a>]: Unable to open '.../wp-content/uploads/2013/04/cafe-rene-india-nespresso-compatible-coffee-capsules-box-of-10-191x191.jpg' for writing: Permission denied in .../wp-includes/class-wp-image-editor.php on line 334 – user2298991 Jan 9 '14 at 23:28
  • codeprotected function make_image( $filename, $function, $arguments ) { $dst_file = $filename; if ( $stream = wp_is_stream( $filename ) ) { $filename = null; ob_start(); } $result = call_user_func_array( $function, $arguments ); if ( $result && $stream ) { $contents = ob_get_contents(); $fp = fopen( $dst_file, 'w' ); if ( ! $fp ) return false; fwrite( $fp, $contents ); fclose( $fp ); } if ( $stream ) { ob_end_clean(); } return $result; }code – user2298991 Jan 9 '14 at 23:35
  • Above is the referenced function, i'm not in PHP, please, any idea how to change it so it wont rewrite existing files but instead just create new files if necessary – user2298991 Jan 9 '14 at 23:36
1

Replacing the WordPress generated images using ftp is not at all a good idea and also would be tiresome for you.

Your problem is about the quality of the image

WordPress’ default compression ratio for image generation is not at 100%.

so you can make it 100% by putting the below code in the active theme's functions.php file

add_filter( 'jpeg_quality', 'wpse_image_full_quality' );
add_filter( 'wp_editor_set_quality', 'wpse_image_full_quality' );

function wpse_image_full_quality( $quality ) {
    return 100;
}

This will only apply to thumbnails and images generated after you have inserted the code into your theme. If you want this to apply to existing images and thumbnails, you should use a plugin like Regenerate Thumbnails to create new, better quality images with the updated compression ratio.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.