Make WordPress Core


Ignore:
Timestamp:
11/22/2012 09:52:16 AM (14 years ago)
Author:
nacin
Message:

WP_Image_Editor: the last stand.

  • Have wp_get_image_editor() rather than WP_Image_Editor::get_instance(). Having static factory methods would be less confusing if there weren't also static methods tied to individual editor implementations.
  • Lazy-load the WP_Image_Editor base class and editor implementations.
  • Have WP_Image_Editor_GD::supports_mime_type() actually check which types it supports.
  • Deprecate gd_edit_image_support() in favor of wp_image_editor_supports().

props DH-Shredder, scribu, markoheijnen. fixes #22356. see #6821.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-wp-image-editor-imagick.php

    r22619 r22817  
    1616 */
    1717class WP_Image_Editor_Imagick extends WP_Image_Editor {
     18
    1819        protected $image = null; // Imagick Object
    1920
    … …  
    3738         * @return boolean
    3839         */
    39         public static function test( $args = null ) {
     40        public static function test( $args = array() ) {
    4041                if ( ! extension_loaded( 'imagick' ) || ! is_callable( 'Imagick', 'queryFormats' ) )
    4142                        return false;
    … …  
    4546
    4647        /**
     48         * Checks to see if editor supports the mime-type specified.
     49         *
     50         * @since 3.5.0
     51         * @access public
     52         *
     53         * @param string $mime_type
     54         * @return boolean
     55         */
     56        public static function supports_mime_type( $mime_type ) {
     57                $imagick_extension = strtoupper( self::get_extension( $mime_type ) );
     58
     59                if ( ! $imagick_extension )
     60                        return false;
     61
     62                try {
     63                        return ( (bool) Imagick::queryFormats( $imagick_extension ) );
     64                }
     65                catch ( Exception $e ) {
     66                        return false;
     67                }
     68        }
     69
     70        /**
    4771         * Loads image from $this->file into new Imagick Object.
    4872         *
    … …  
    5276         * @return boolean|WP_Error True if loaded; WP_Error on failure.
    5377         */
    54         protected function load() {
     78        public function load() {
    5579                if ( $this->image )
    5680                        return true;
    … …  
    136160
    137161                return parent::update_size( $width, $height );
    138         }
    139 
    140         /**
    141          * Checks to see if editor supports the mime-type specified.
    142          *
    143          * @since 3.5.0
    144          * @access public
    145          *
    146          * @param string $mime_type
    147          * @return boolean
    148          */
    149         public static function supports_mime_type( $mime_type ) {
    150                 if ( ! $mime_type )
    151                         return false;
    152 
    153                 $imagick_extension = strtoupper( self::get_extension( $mime_type ) );
    154 
    155                 try {
    156                         return ( (bool) Imagick::queryFormats( $imagick_extension ) );
    157                 }
    158                 catch ( Exception $e ) {
    159                         return false;
    160                 }
    161162        }
    162163
    … …  
    313314         * @access public
    314315         *
    315          * @param boolean $horz Horizonal Flip
     316         * @param boolean $horz Horizontal Flip
    316317         * @param boolean $vert Vertical Flip
    317318         * @returns boolean|WP_Error
Note: See TracChangeset for help on using the changeset viewer.