16
16
protected $size = null;
17
17
protected $mime_type = null;
18
18
protected $default_mime_type = 'image/jpeg';
19
protected $quality = 90;
19
protected $quality = false;
20
protected $default_quality = 90;
22
23
* Each instance handles a single file.
207
* Gets the Image Compression quality on a 1-100% scale.
212
* @return int $quality Compression Quality. Range: [1,100]
214
public function get_quality() {
215
if ( ! $this->quality ) {
217
* Filter the default image compression quality setting.
221
* @param int $quality Quality level between 1 (low) and 100 (high).
222
* @param string $mime_type Image mime type.
224
$quality = apply_filters( 'wp_editor_set_quality', $this->default_quality, $this->mime_type );
226
if ( 'image/jpeg' == $this->mime_type ) {
228
* Filter the JPEG compression quality for backward-compatibility.
230
* The filter is evaluated under two contexts: 'image_resize', and 'edit_image',
231
* (when a JPEG image is saved to file).
235
* @param int $quality Quality level between 0 (low) and 100 (high) of the JPEG.
236
* @param string $context Context of the filter.
238
$quality = apply_filters( 'jpeg_quality', $quality, 'image_resize' );
240
if ( ! $this->set_quality( $quality ) ) {
241
$this->quality = $this->default_quality;
246
return $this->quality;
206
250
* Sets Image Compression quality on a 1-100% scale.
212
256
* @return boolean|WP_Error True if set successfully; WP_Error on failure.
214
258
public function set_quality( $quality = null ) {
215
if ( $quality == null ) {
216
$quality = $this->quality;
220
* Filter the default image compression quality setting.
224
* @param int $quality Quality level between 1 (low) and 100 (high).
225
* @param string $mime_type Image mime type.
227
$quality = apply_filters( 'wp_editor_set_quality', $quality, $this->mime_type );
229
if ( 'image/jpeg' == $this->mime_type ) {
231
* Filter the JPEG compression quality for backward-compatibility.
233
* The filter is evaluated under two contexts: 'image_resize', and 'edit_image',
234
* (when a JPEG image is saved to file).
238
* @param int $quality Quality level between 0 (low) and 100 (high) of the JPEG.
239
* @param string $context Context of the filter.
241
$quality = apply_filters( 'jpeg_quality', $quality, 'image_resize' );
243
// Allow 0, but squash to 1 due to identical images in GD, and for backwards compatibility.
244
if ( $quality == 0 ) {
249
if ( ( $quality >= 1 ) && ( $quality <= 100 ) ){
259
// Allow 0, but squash to 1 due to identical images in GD, and for backwards compatibility.
260
if ( $quality == 0 ) {
264
if ( ( $quality >= 1 ) && ( $quality <= 100 ) ) {
250
265
$this->quality = $quality;
270
285
* @return array { filename|null, extension, mime-type }
272
287
protected function get_output_format( $filename = null, $mime_type = null ) {
273
$new_ext = $file_ext = null;
276
290
// By default, assume specified type takes priority
277
291
if ( $mime_type ) {