wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
wp_get_image_encode_quality › WordPress Function
Seit7.1.0
Veraltetn/v
› wp_get_image_encode_quality ( $mime_type, $size = array(), $default_quality = null )
| Parameter: (3) |
|
| Gibt zurück: |
|
| Definiert in: |
|
| Codex: |
Determines the encode quality WordPress would use for an image.
Resolves the quality the same way WP_Image_Editor::set_quality() does when no explicit quality is supplied: it starts from the per-format default, applies the 'wp_editor_set_quality' filter, then the 'jpeg_quality' filter for JPEG output, resets out-of-range values to the per-format default, and squashes 0 to 1. This lets code outside of an image editor instance - such as the REST API, which reports the quality client-side processing should use - resolve the same value the server would apply, without loading the image into an editor.Ähnliche Funktionen: wp_get_image_editor, wp_get_image_alttext, wp_get_widget_defaults, wp_get_image_mime, get_image_send_to_editor
Quellcode
function wp_get_image_encode_quality( string $mime_type, array $size = array(), ?int $default_quality = null ): int {
if ( null === $default_quality ) {
// Mirror WP_Image_Editor::get_default_quality(): WebP defaults to 86, everything else to 82.
$default_quality = ( 'image/webp' === $mime_type ) ? 86 : 82;
}
/** This filter is documented in wp-includes/class-wp-image-editor.php */
$quality = apply_filters( 'wp_editor_set_quality', $default_quality, $mime_type, $size );
if ( 'image/jpeg' === $mime_type ) {
/** This filter is documented in wp-includes/class-wp-image-editor.php */
$quality = apply_filters( 'jpeg_quality', $quality, 'image_resize' );
}
if ( ! is_numeric( $quality ) ) {
$quality = $default_quality;
} else {
$quality = (int) $quality;
}
// Reset out-of-range values to the default, matching WP_Image_Editor::set_quality().
if ( $quality < 0 || $quality > 100 ) {
$quality = $default_quality;
}
// Allow 0, but squash to 1, matching WP_Image_Editor::set_quality().
if ( 0 === $quality ) {
$quality = 1;
}
return $quality;
}