Sharpen resized images and interlace option in WordPress

Have you ever notice that some resized images in WordPress look blurry, and you would like to dynamically sharpen those images without a bloated plugin.

Well, here is how, you can sharpen the resized images in WordPress; and while you are at it you can also activate the interlace option on all image.

Interlaced images even though are bigger, they allow web pages to load faster because all data is not loaded all at once but gradually.

Add the following code to the functions.php file in your theme:

function modify_image_before_saving( $image, $post_id ){
	if ( 'attachment' == get_post_type( $postid ) )
		return $image;
	
	//add interlace image option
	imageinterlace( $image, true );

        // sharpen image
	imageconvolution( $image, array(-1,-1,-1,-1,16,-1,-1,-1,-1) , 8, 0 );
	
	return $image;
}
add_filter( 'image_save_pre','modify_image_before_saving', 15, 2 );

That is it, now you have sharper images and web pages that load faster.