Changeset 42343 for trunk/src/wp-includes/class-wp-image-editor.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-image-editor.php
r41288 r42343 13 13 */ 14 14 abstract class WP_Image_Editor { 15 protected $file = null;16 protected $size = null;17 protected $mime_type = null;15 protected $file = null; 16 protected $size = null; 17 protected $mime_type = null; 18 18 protected $default_mime_type = 'image/jpeg'; 19 protected $quality = false;20 protected $default_quality = 82;19 protected $quality = false; 20 protected $default_quality = 82; 21 21 22 22 /** … … 192 192 protected function update_size( $width = null, $height = null ) { 193 193 $this->size = array( 194 'width' => (int) $width,195 'height' => (int) $height 194 'width' => (int) $width, 195 'height' => (int) $height, 196 196 ); 197 197 return true; … … 272 272 return true; 273 273 } else { 274 return new WP_Error( 'invalid_image_quality', __( 'Attempted to set image quality outside of the range [1,100].') );274 return new WP_Error( 'invalid_image_quality', __( 'Attempted to set image quality outside of the range [1,100].' ) ); 275 275 } 276 276 } … … 299 299 300 300 if ( $filename ) { 301 $file_ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );301 $file_ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) ); 302 302 $file_mime = $this->get_mime_type( $file_ext ); 303 } 304 else { 303 } else { 305 304 // If no file specified, grab editor's current extension and mime-type. 306 $file_ext = strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) );305 $file_ext = strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) ); 307 306 $file_mime = $this->mime_type; 308 307 } … … 312 311 if ( ! $mime_type || ( $file_mime == $mime_type ) ) { 313 312 $mime_type = $file_mime; 314 $new_ext = $file_ext;313 $new_ext = $file_ext; 315 314 } 316 315 … … 328 327 */ 329 328 $mime_type = apply_filters( 'image_editor_default_mime_type', $this->default_mime_type ); 330 $new_ext = $this->get_extension( $mime_type );329 $new_ext = $this->get_extension( $mime_type ); 331 330 } 332 331 … … 353 352 public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) { 354 353 // $suffix will be appended to the destination filename, just before the extension 355 if ( ! $suffix ) 354 if ( ! $suffix ) { 356 355 $suffix = $this->get_suffix(); 357 358 $dir = pathinfo( $this->file, PATHINFO_DIRNAME ); 359 $ext = pathinfo( $this->file, PATHINFO_EXTENSION ); 360 361 $name = wp_basename( $this->file, ".$ext" ); 356 } 357 358 $dir = pathinfo( $this->file, PATHINFO_DIRNAME ); 359 $ext = pathinfo( $this->file, PATHINFO_EXTENSION ); 360 361 $name = wp_basename( $this->file, ".$ext" ); 362 362 $new_ext = strtolower( $extension ? $extension : $ext ); 363 363 364 if ( ! is_null( $dest_path ) && $_dest_path = realpath( $dest_path ) ) 364 if ( ! is_null( $dest_path ) && $_dest_path = realpath( $dest_path ) ) { 365 365 $dir = $_dest_path; 366 } 366 367 367 368 return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}"; … … 376 377 */ 377 378 public function get_suffix() { 378 if ( ! $this->get_size() ) 379 if ( ! $this->get_size() ) { 379 380 return false; 381 } 380 382 381 383 return "{$this->size['width']}x{$this->size['height']}"; … … 407 409 $fp = fopen( $filename, 'w' ); 408 410 409 if ( ! $fp ) 411 if ( ! $fp ) { 410 412 return false; 413 } 411 414 412 415 fwrite( $fp, $contents ); … … 433 436 */ 434 437 protected static function get_mime_type( $extension = null ) { 435 if ( ! $extension ) 438 if ( ! $extension ) { 436 439 return false; 440 } 437 441 438 442 $mime_types = wp_get_mime_types(); … … 441 445 foreach ( $extensions as $_extension ) { 442 446 if ( preg_match( "/{$extension}/i", $_extension ) ) { 443 return $mime_types[ $_extension];447 return $mime_types[ $_extension ]; 444 448 } 445 449 } … … 462 466 $extensions = explode( '|', array_search( $mime_type, wp_get_mime_types() ) ); 463 467 464 if ( empty( $extensions[0] ) ) 468 if ( empty( $extensions[0] ) ) { 465 469 return false; 470 } 466 471 467 472 return $extensions[0];
Note: See TracChangeset
for help on using the changeset viewer.