Changeset 22817 for trunk/wp-includes/class-wp-image-editor.php
- Timestamp:
- 11/22/2012 09:52:16 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-wp-image-editor.php
r22619 r22817 8 8 9 9 /** 10 * Base WordPress Image Editor class for which Editorimplementations extend10 * Base image editor class from which implementations extend 11 11 * 12 12 * @since 3.5.0 … … 15 15 protected $file = null; 16 16 protected $size = null; 17 protected $mime_type 17 protected $mime_type = null; 18 18 protected $default_mime_type = 'image/jpeg'; 19 19 protected $quality = 90; 20 20 21 protected function __construct( $filename ) { 22 $this->file = $filename; 23 } 24 25 /** 26 * Returns a WP_Image_Editor instance and loads file into it. 27 * 28 * @since 3.5.0 29 * @access public 30 * 31 * @param string $path Path to File to Load 32 * @param array $required_methods Methods to require in implementation 33 * @return WP_Image_Editor|WP_Error 34 */ 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 38 if ( $implementation ) { 39 $editor = new $implementation( $path ); 40 $loaded = $editor->load(); 41 42 if ( is_wp_error( $loaded ) ) 43 return $loaded; 44 45 return $editor; 46 } 47 48 return new WP_Error( 'no_editor', __('No editor could be selected') ); 49 } 50 51 /** 52 * Tests which editors are capable of supporting the request. 53 * 54 * @since 3.5.0 55 * @access private 56 * 57 * @param array $required_methods String array of all methods required for implementation returned. 58 * @return string|bool Class name for the first editor that claims to support the request. False if no editor claims to support the request. 59 */ 60 private final static function choose_implementation( $required_methods = null ) { 61 $request_order = apply_filters( 'wp_image_editors', 62 array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) ); 63 64 if ( ! $required_methods ) 65 $required_methods = array(); 66 67 // Loop over each editor on each request looking for one which will serve this request's needs 68 foreach ( $request_order as $editor ) { 69 // Check to see if this editor is a possibility, calls the editor statically 70 if ( ! call_user_func( array( $editor, 'test' ) ) ) 71 continue; 72 73 // Make sure that all methods are supported by editor. 74 if ( array_diff( $required_methods, get_class_methods( $editor ) ) ) 75 continue; 76 77 return $editor; 78 } 21 /** 22 * Each instance handles a single file. 23 */ 24 public function __construct( $file ) { 25 $this->file = $file; 26 } 27 28 /** 29 * Checks to see if current environment supports the editor chosen. 30 * Must be overridden in a sub-class. 31 * 32 * @since 3.5.0 33 * @access public 34 * @abstract 35 * 36 * @param array $args 37 * @return boolean 38 */ 39 public static function test( $args = array() ) { 79 40 return false; 80 41 } 81 42 82 43 /** 44 * Checks to see if editor supports the mime-type specified. 45 * Must be overridden in a sub-class. 46 * 47 * @since 3.5.0 48 * @access public 49 * @abstract 50 * 51 * @param string $mime_type 52 * @return boolean 53 */ 54 public static function supports_mime_type( $mime_type ) { 55 return false; 56 } 57 58 /** 83 59 * Loads image from $this->file into editor. 84 60 * … … 89 65 * @return boolean|WP_Error True if loaded; WP_Error on failure. 90 66 */ 91 abstract p rotectedfunction load();67 abstract public function load(); 92 68 93 69 /** … … 169 145 * @abstract 170 146 * 171 * @param boolean $horz Horizon al Flip147 * @param boolean $horz Horizontal Flip 172 148 * @param boolean $vert Vertical Flip 173 149 * @return boolean|WP_Error … … 186 162 */ 187 163 abstract public function stream( $mime_type = null ); 188 189 /**190 * Checks to see if current environment supports the editor chosen.191 * Must be overridden in a sub-class.192 *193 * @since 3.5.0194 * @access public195 * @abstract196 *197 * @param array $args198 * @return boolean199 */200 public static function test( $args = null ) {201 return false;202 }203 204 /**205 * Checks to see if editor supports the mime-type specified.206 * Must be overridden in a sub-class.207 *208 * @since 3.5.0209 * @access public210 * @abstract211 *212 * @param string $mime_type213 * @return boolean214 */215 public static function supports_mime_type( $mime_type ) {216 return false;217 }218 164 219 165 /** … … 452 398 } 453 399 } 400
Note: See TracChangeset
for help on using the changeset viewer.