Last active
October 13, 2017 16:47
-
-
Save humbertocastelo/7b24192d88015618fc5e39a4bcc3546a to your computer and use it in GitHub Desktop.
wp_editor_set_quality and jpeg_quality
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_prefix_wp_editor_set_quality( $quality, $mime_type ) { | |
if ( $mime_type === 'image/jpeg' ) { | |
$quality = 90; | |
} elseif ( $mime_type === 'image/png' ) { | |
$quality = 91; | |
} elseif ( $mime_type === 'image/gif' ) { | |
$quality = 92; | |
} else { | |
$quality = 93; | |
} | |
return $quality; | |
} | |
add_filter( 'wp_editor_set_quality', 'my_prefix_wp_editor_set_quality', 10, 2 ); | |
function my_prefix_jpeg_quality( $quality, $context ) { | |
if ( $context === 'edit_image' ) { | |
$quality = 94; | |
} elseif ( $context === 'image_resize' ) { | |
$quality = 95; | |
} else { | |
$quality = 96; | |
} | |
return $quality; | |
} | |
add_filter( 'jpeg_quality', 'my_prefix_jpeg_quality', 10, 2 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment