Skip to content

Instantly share code, notes, and snippets.

@stephanieleary
Last active September 13, 2019 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephanieleary/38d7a4d2fa127e2da00468da8c499413 to your computer and use it in GitHub Desktop.
Save stephanieleary/38d7a4d2fa127e2da00468da8c499413 to your computer and use it in GitHub Desktop.
Filter PNG image quality in WordPress
<?php
// well-known filter to change JPG quality:
add_filter( 'jpeg_quality', function( $arg ){ return 100; } );
// lesser-known filter to change quality for any image type:
add_filter( 'wp_editor_set_quality', 'any_image_quality', 10, 2 );
add_filter( 'jpeg_quality', 'any_image_quality' );
function any_image_quality( $default_quality, $mime_type = NULL ) {
// you could do if ( 'image/png' == $mime_type ) here if you want to be specific
return 100;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment