Skip to content

Instantly share code, notes, and snippets.

@kirstenschelper
Last active October 3, 2017 10:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirstenschelper/824289ceeeb81ca65dc37e61d614dbb6 to your computer and use it in GitHub Desktop.
Save kirstenschelper/824289ceeeb81ca65dc37e61d614dbb6 to your computer and use it in GitHub Desktop.
Sharpen small images sizes generated by WP
// Zu diesem Code gibt es einen Artikel im Blog die-netzialisten.de
// https://die-netzialisten.de/wordpress/unscharfe-beitragsbilder-nachschaerfen/
function ks_sharpen_resized_files( $resized_file ) {
$image = imagecreatefromstring( file_get_contents( $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', 'ks_sharpen_resized_files',900);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment