WP_Image_Editor_Imagick::set_quality()
Sets Image Compression quality on a 1-100% scale.
Метод класса: WP_Image_Editor_Imagick{}
Хуков нет.
Возвращает
true|WP_Error
. True if set successfully; WP_Error on failure.
Использование
$WP_Image_Editor_Imagick = new WP_Image_Editor_Imagick(); $WP_Image_Editor_Imagick->set_quality( $quality );
- $quality(int)
- Compression Quality. Range: [1,100]
По умолчанию: null
Список изменений
С версии 3.5.0 | Введена. |
Код WP_Image_Editor_Imagick::set_quality() WP Image Editor Imagick::set quality WP 6.7.1
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->setCompressionQuality( $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->setCompressionQuality( 100 ); $this->image->setOption( 'webp:lossless', 'true' ); parent::set_quality( 100 ); } else { $this->image->setImageCompressionQuality( $quality ); $this->image->setCompressionQuality( $quality ); } break; case 'image/avif': // Set the AVIF encoder to work faster, with minimal impact on image size. $this->image->setOption( 'heic:speed', 7 ); $this->image->setImageCompressionQuality( $quality ); $this->image->setCompressionQuality( $quality ); break; default: $this->image->setImageCompressionQuality( $quality ); $this->image->setCompressionQuality( $quality ); } } catch ( Exception $e ) { return new WP_Error( 'image_quality_error', $e->getMessage() ); } return true; }