Changeset 22510
- Timestamp:
- 11/09/2012 07:38:54 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/image-edit.php
r22192 r22510 238 238 /** 239 239 * Saves Image to File 240 * @TODO: Add mime_type support to WP_Image_Editor241 240 * 242 241 * @param string $filename -
trunk/wp-includes/class-wp-image-editor-gd.php
r22463 r22510 29 29 * 30 30 * @since 3.5.0 31 * @access p rotected31 * @access public 32 32 * 33 33 * @return boolean 34 34 */ 35 public function test() {35 public static function test( $args = null ) { 36 36 if ( ! extension_loaded('gd') || ! function_exists('gd_info') ) 37 37 return false; … … 100 100 * @return boolean 101 101 */ 102 public function supports_mime_type( $mime_type ) {102 public static function supports_mime_type( $mime_type ) { 103 103 $allowed_mime_types = array( 'image/gif', 'image/png', 'image/jpeg' ); 104 104 -
trunk/wp-includes/class-wp-image-editor-imagick.php
r22463 r22510 30 30 * 31 31 * @since 3.5.0 32 * @access p rotected32 * @access public 33 33 * 34 34 * @return boolean 35 35 */ 36 public function test() {36 public static function test( $args = null ) { 37 37 if ( ! extension_loaded( 'imagick' ) ) 38 38 return false; … … 144 144 * @return boolean 145 145 */ 146 public function supports_mime_type( $mime_type ) {146 public static function supports_mime_type( $mime_type ) { 147 147 if ( ! $mime_type ) 148 148 return false; -
trunk/wp-includes/class-wp-image-editor.php
r22243 r22510 18 18 protected $default_mime_type = 'image/jpeg'; 19 19 protected $quality = 90; 20 private static $implementation;21 20 22 21 protected function __construct( $filename ) { … … 31 30 * 32 31 * @param string $path Path to File to Load 32 * @param array $required_methods Methods to require in implementation 33 33 * @return WP_Image_Editor|WP_Error|boolean 34 34 */ 35 public final static function get_instance( $path = null ) {36 $implementation = apply_filters( ' image_editor_class', self::choose_implementation(), $path );35 public final static function get_instance( $path = null, $required_methods = null ) { 36 $implementation = apply_filters( 'wp_image_editor_class', self::choose_implementation( $required_methods ), $path ); 37 37 38 38 if ( $implementation ) { … … 40 40 $loaded = $editor->load(); 41 41 42 if ( is_wp_error 42 if ( is_wp_error( $loaded ) ) 43 43 return $loaded; 44 44 … … 55 55 * @access private 56 56 * 57 * @param $required_methods Array String array of all methods required for implementation returned. 58 * 57 59 * @return string|bool Class name for the first editor that claims to support the request. False if no editor claims to support the request. 58 60 */ 59 private final static function choose_implementation() { 60 61 if ( null === self::$implementation ) { 62 $request_order = apply_filters( 'wp_editors', array( 'imagick', 'gd' ) ); 63 64 // Loop over each editor on each request looking for one which will serve this request's needs 65 foreach ( $request_order as $editor ) { 66 $class = 'WP_Image_Editor_' . $editor; 67 68 // Check to see if this editor is a possibility, calls the editor statically 69 if ( ! call_user_func( array( $class, 'test' ) ) ) 70 continue; 71 72 self::$implementation = $class; 73 break; 74 } 75 } 76 return self::$implementation; 77 } 78 79 abstract public function test(); // returns bool 61 private final static function choose_implementation( $required_methods = null ) { 62 $request_order = apply_filters( 'wp_image_editors', 63 array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) ); 64 65 if ( ! $required_methods ) 66 $required_methods = apply_filters( 'wp_image_editor_default_methods', 67 array( 'resize', 'multi_resize', 'crop', 'rotate', 'flip', 'stream' ) ); 68 69 // Loop over each editor on each request looking for one which will serve this request's needs 70 foreach ( $request_order as $editor ) { 71 // Check to see if this editor is a possibility, calls the editor statically 72 if ( ! call_user_func( array( $editor, 'test' ) ) ) 73 continue; 74 75 // Make sure that all methods are supported by editor. 76 if ( array_diff( $required_methods, get_class_methods( $editor ) ) ) 77 continue; 78 79 return $editor; 80 } 81 return false; 82 } 83 80 84 abstract protected function load(); // returns bool|WP_Error 81 abstract public function supports_mime_type( $mime_type ); // returns bool82 abstract public function resize( $max_w, $max_h, $crop = false );83 abstract public function multi_resize( $sizes );84 abstract public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false );85 abstract public function rotate( $angle );86 abstract public function flip( $horz, $vert );87 85 abstract public function save( $destfilename = null, $mime_type = null ); 88 abstract public function stream( $mime_type = null ); 86 87 /** 88 * Implement all of the below to support natively used functions: 89 * 90 * public function resize( $max_w, $max_h, $crop = false ) 91 * public function multi_resize( $sizes ) 92 * public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) 93 * public function rotate( $angle ) 94 * public function flip( $horz, $vert ) 95 * public function stream( $mime_type = null ) 96 */ 97 98 /** 99 * Checks to see if current environment supports the editor chosen. 100 * Must be overridden in a sub-class. 101 * 102 * @since 3.5.0 103 * @access public 104 * @abstract 105 * 106 * @param $args array 107 * @return boolean 108 */ 109 public static function test( $args = null ) { 110 return false; 111 } 112 113 /** 114 * Checks to see if editor supports mime-type specified 115 * Must be overridden in a sub-class. 116 * 117 * @since 3.5.0 118 * @access public 119 * @abstract 120 * 121 * @param string $mime_type 122 * @return boolean 123 */ 124 public static function supports_mime_type( $mime_type ) { 125 return false; 126 } 89 127 90 128 /** … … 259 297 $result = call_user_func_array( $function, $arguments ); 260 298 261 if ( $result && $stream ) {299 if ( $result && $stream ) { 262 300 $contents = ob_get_contents(); 263 301 264 302 $fp = fopen( $dst_file, 'w' ); 265 303 266 if ( ! $fp )304 if ( ! $fp ) 267 305 return false; 268 306 … … 271 309 } 272 310 273 if ( $stream ) {311 if ( $stream ) { 274 312 ob_end_clean(); 275 313 } … … 296 334 297 335 foreach( $extensions as $_extension ) { 298 if ( preg_match("/{$extension}/i", $_extension ) ) {299 return $mime_types[ $_extension];336 if ( preg_match( "/{$extension}/i", $_extension ) ) { 337 return $mime_types[$_extension]; 300 338 } 301 339 }
Note: See TracChangeset
for help on using the changeset viewer.