WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/22/2012 09:52:16 AM (9 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-gd.php

    r22619 r22817  
    1616 */
    1717class WP_Image_Editor_GD extends WP_Image_Editor {
     18
    1819    protected $image = false; // GD Resource
    1920
     
    3334     * @return boolean
    3435     */
    35     public static function test( $args = null ) {
     36    public static function test( $args = array() ) {
    3637        if ( ! extension_loaded('gd') || ! function_exists('gd_info') )
    3738            return false;
     
    4142
    4243    /**
     44     * Checks to see if editor supports the mime-type specified.
     45     *
     46     * @since 3.5.0
     47     * @access public
     48     *
     49     * @param string $mime_type
     50     * @return boolean
     51     */
     52    public static function supports_mime_type( $mime_type ) {
     53        $image_types = imagetypes();
     54        switch( $mime_type ) {
     55            case 'image/jpeg':
     56                return ($image_types & IMG_JPG) != 0;
     57            case 'image/png':
     58                return ($image_types & IMG_PNG) != 0;
     59            case 'image/gif':
     60                return ($image_types & IMG_GIF) != 0;
     61        }
     62
     63        return false;
     64    }
     65
     66    /**
    4367     * Loads image from $this->file into new GD Resource.
    4468     *
     
    4872     * @return boolean|\WP_Error
    4973     */
    50     protected function load() {
     74    public function load() {
    5175        if ( $this->image )
    5276            return true;
     
    89113
    90114        return parent::update_size( $width, $height );
    91     }
    92 
    93     /**
    94      * Checks to see if editor supports the mime-type specified.
    95      *
    96      * @since 3.5.0
    97      * @access public
    98      *
    99      * @param string $mime_type
    100      * @return boolean
    101      */
    102     public static function supports_mime_type( $mime_type ) {
    103         $allowed_mime_types = array( 'image/gif', 'image/png', 'image/jpeg' );
    104 
    105         return in_array( $mime_type, $allowed_mime_types );
    106115    }
    107116
     
    262271     * @access public
    263272     *
    264      * @param boolean $horz Horizonal Flip
     273     * @param boolean $horz Horizontal Flip
    265274     * @param boolean $vert Vertical Flip
    266275     * @returns boolean|WP_Error
Note: See TracChangeset for help on using the changeset viewer.