Scroll Down
/**
* code #17 - sharpen JPG/JPEG images when auto-resized in WordPress
* source - http://wordpress.stackexchange.com/a/35526/8922
* @param string
* @return resource
*/
function sharpen_resized_jpeg_images($resized_file) {
$image = wp_load_image($resized_file);
if(!is_resource($image))
return new WP_Error('error_loading_image', $image, $file);
$size = @getimagesize($resized_file);
if(!$size)
return new WP_Error('invalid_image', __('Could not read image size'), $file);
list($orig_w, $orig_h, $orig_type) = $size;
switch($orig_type) {
case IMAGETYPE_JPEG:
$matrix = array(
array(-1, -1, -1),
array(-1, 16, -1),
array(-1, -1, -1),
);
$divisor = array_sum(array_map('array_sum', $matrix));
$offset = 0;
imageconvolution($image, $matrix, $divisor, $offset);
imagejpeg($image, $resized_file,apply_filters('jpeg_quality', 90, 'edit_image'));
break;
case IMAGETYPE_PNG:
return $resized_file;
case IMAGETYPE_GIF:
return $resized_file;
}
return $resized_file;
}
add_filter('image_make_intermediate_size', 'sharpen_resized_jpeg_images', 900);
Please note upfront that this code will only work for JPG/JPEG image types. However that being said, this is definitely worth using in your code if you ever upload jpegs. If you go to the original stack comment you can see a few example comparison images. There is clearly a huge different in quality and it’s a very impressive customization.