WP_Image_Editor_Imagick::set_quality() WordPress Method
The WP_Image_Editor_Imagick::set_quality() method is used to set the image quality for the editor. This is useful for ensuring that the image is of the highest quality when it is saved.
WP_Image_Editor_Imagick::set_quality( int $quality = null ) #
Sets Image Compression quality on a 1-100% scale.
Parameters
- $quality
(int)(Optional)Compression Quality. Range: [1,100]
Default value: null
Return
(true|WP_Error) True if set successfully; WP_Error on failure.
Source
File: wp-includes/class-wp-image-editor-imagick.php
public function set_quality( $quality = null ) { $quality_result = parent::set_quality( $quality ); if ( is_wp_error( $quality_result ) ) { return $quality_result; } else { $quality = $this->get_quality(); } try { switch ( $this->mime_type ) { case 'image/jpeg': $this->image->setImageCompressionQuality( $quality ); $this->image->setImageCompression( imagick::COMPRESSION_JPEG ); break; case 'image/webp': $webp_info = wp_get_webp_info( $this->file ); if ( 'lossless' === $webp_info['type'] ) { // Use WebP lossless settings. $this->image->setImageCompressionQuality( 100 ); $this->image->setOption( 'webp:lossless', 'true' ); } else { $this->image->setImageCompressionQuality( $quality ); } break; default: $this->image->setImageCompressionQuality( $quality ); } } catch ( Exception $e ) { return new WP_Error( 'image_quality_error', $e->getMessage() ); } return true; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
3.5.0 | Introduced. |