~canonical-sysadmins/wordpress/4.7

« back to all changes in this revision

Viewing changes to wp-includes/class-wp-image-editor.php

  • Committer: Nick Moffitt
  • Date: 2015-01-15 11:04:26 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: nick.moffitt@canonical.com-20150115110426-5stm1p14cfnxrtme
New Upstream Version 4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
213
213
         */
214
214
        public function get_quality() {
215
215
                if ( ! $this->quality ) {
 
216
                        $this->set_quality();
 
217
                }
 
218
 
 
219
                return $this->quality;
 
220
        }
 
221
 
 
222
        /**
 
223
         * Sets Image Compression quality on a 1-100% scale.
 
224
         *
 
225
         * @since 3.5.0
 
226
         * @access public
 
227
         *
 
228
         * @param int $quality Compression Quality. Range: [1,100]
 
229
         * @return boolean|WP_Error True if set successfully; WP_Error on failure.
 
230
         */
 
231
        public function set_quality( $quality = null ) {
 
232
                if ( null === $quality ) {
216
233
                        /**
217
234
                         * Filter the default image compression quality setting.
218
235
                         *
 
236
                         * Applies only during initial editor instantiation, or when set_quality() is run
 
237
                         * manually without the `$quality` argument.
 
238
                         *
 
239
                         * set_quality() has priority over the filter.
 
240
                         *
219
241
                         * @since 3.5.0
220
242
                         *
221
243
                         * @param int    $quality   Quality level between 1 (low) and 100 (high).
227
249
                                /**
228
250
                                 * Filter the JPEG compression quality for backward-compatibility.
229
251
                                 *
 
252
                                 * Applies only during initial editor instantiation, or when set_quality() is run
 
253
                                 * manually without the `$quality` argument.
 
254
                                 *
 
255
                                 * set_quality() has priority over the filter.
 
256
                                 *
230
257
                                 * The filter is evaluated under two contexts: 'image_resize', and 'edit_image',
231
258
                                 * (when a JPEG image is saved to file).
232
259
                                 *
236
263
                                 * @param string $context Context of the filter.
237
264
                                 */
238
265
                                $quality = apply_filters( 'jpeg_quality', $quality, 'image_resize' );
 
266
                        }
239
267
 
240
 
                                if ( ! $this->set_quality( $quality ) ) {
241
 
                                        $this->quality = $this->default_quality;
242
 
                                }
 
268
                        if ( $quality < 0 || $quality > 100 ) {
 
269
                                $quality = $this->default_quality;
243
270
                        }
244
271
                }
245
272
 
246
 
                return $this->quality;
247
 
        }
248
 
 
249
 
        /**
250
 
         * Sets Image Compression quality on a 1-100% scale.
251
 
         *
252
 
         * @since 3.5.0
253
 
         * @access public
254
 
         *
255
 
         * @param int $quality Compression Quality. Range: [1,100]
256
 
         * @return boolean|WP_Error True if set successfully; WP_Error on failure.
257
 
         */
258
 
        public function set_quality( $quality = null ) {
259
273
                // Allow 0, but squash to 1 due to identical images in GD, and for backwards compatibility.
260
 
                if ( $quality == 0 ) {
 
274
                if ( 0 === $quality ) {
261
275
                        $quality = 1;
262
276
                }
263
277