~ubuntu-branches/debian/sid/wordpress/sid

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Craig Small
  • Date: 2014-09-05 20:58:06 UTC
  • mfrom: (1.2.38)
  • Revision ID: package-import@ubuntu.com-20140905205806-e4h6dkg4190n0svf
Tags: 4.0+dfsg-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
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;
20
21
 
21
22
        /**
22
23
         * Each instance handles a single file.
203
204
        }
204
205
 
205
206
        /**
 
207
         * Gets the Image Compression quality on a 1-100% scale.
 
208
         *
 
209
         * @since 4.0.0
 
210
         * @access public
 
211
         *
 
212
         * @return int $quality Compression Quality. Range: [1,100]
 
213
         */
 
214
        public function get_quality() {
 
215
                if ( ! $this->quality ) {
 
216
                        /**
 
217
                         * Filter the default image compression quality setting.
 
218
                         *
 
219
                         * @since 3.5.0
 
220
                         *
 
221
                         * @param int    $quality   Quality level between 1 (low) and 100 (high).
 
222
                         * @param string $mime_type Image mime type.
 
223
                         */
 
224
                        $quality = apply_filters( 'wp_editor_set_quality', $this->default_quality, $this->mime_type );
 
225
 
 
226
                        if ( 'image/jpeg' == $this->mime_type ) {
 
227
                                /**
 
228
                                 * Filter the JPEG compression quality for backward-compatibility.
 
229
                                 *
 
230
                                 * The filter is evaluated under two contexts: 'image_resize', and 'edit_image',
 
231
                                 * (when a JPEG image is saved to file).
 
232
                                 *
 
233
                                 * @since 2.5.0
 
234
                                 *
 
235
                                 * @param int    $quality Quality level between 0 (low) and 100 (high) of the JPEG.
 
236
                                 * @param string $context Context of the filter.
 
237
                                 */
 
238
                                $quality = apply_filters( 'jpeg_quality', $quality, 'image_resize' );
 
239
 
 
240
                                if ( ! $this->set_quality( $quality ) ) {
 
241
                                        $this->quality = $this->default_quality;
 
242
                                }
 
243
                        }
 
244
                }
 
245
 
 
246
                return $this->quality;
 
247
        }
 
248
 
 
249
        /**
206
250
         * Sets Image Compression quality on a 1-100% scale.
207
251
         *
208
252
         * @since 3.5.0
212
256
         * @return boolean|WP_Error True if set successfully; WP_Error on failure.
213
257
         */
214
258
        public function set_quality( $quality = null ) {
215
 
                if ( $quality == null ) {
216
 
                        $quality = $this->quality;
217
 
                }
218
 
 
219
 
                /**
220
 
                 * Filter the default image compression quality setting.
221
 
                 *
222
 
                 * @since 3.5.0
223
 
                 *
224
 
                 * @param int    $quality   Quality level between 1 (low) and 100 (high).
225
 
                 * @param string $mime_type Image mime type.
226
 
                 */
227
 
                $quality = apply_filters( 'wp_editor_set_quality', $quality, $this->mime_type );
228
 
 
229
 
                if ( 'image/jpeg' == $this->mime_type ) {
230
 
                        /**
231
 
                         * Filter the JPEG compression quality for backward-compatibility.
232
 
                         *
233
 
                         * The filter is evaluated under two contexts: 'image_resize', and 'edit_image',
234
 
                         * (when a JPEG image is saved to file).
235
 
                         *
236
 
                         * @since 2.5.0
237
 
                         *
238
 
                         * @param int    $quality Quality level between 0 (low) and 100 (high) of the JPEG.
239
 
                         * @param string $context Context of the filter.
240
 
                         */
241
 
                        $quality = apply_filters( 'jpeg_quality', $quality, 'image_resize' );
242
 
 
243
 
                        // Allow 0, but squash to 1 due to identical images in GD, and for backwards compatibility.
244
 
                        if ( $quality == 0 ) {
245
 
                                $quality = 1;
246
 
                        }
247
 
                }
248
 
 
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 ) {
 
261
                        $quality = 1;
 
262
                }
 
263
 
 
264
                if ( ( $quality >= 1 ) && ( $quality <= 100 ) ) {
250
265
                        $this->quality = $quality;
251
266
                        return true;
252
267
                } else {
270
285
         * @return array { filename|null, extension, mime-type }
271
286
         */
272
287
        protected function get_output_format( $filename = null, $mime_type = null ) {
273
 
                $new_ext = $file_ext = null;
274
 
                $file_mime = null;
 
288
                $new_ext = null;
275
289
 
276
290
                // By default, assume specified type takes priority
277
291
                if ( $mime_type ) {