<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[22817] trunk: WP_Image_Editor: the last stand.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/22817">22817</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2012-11-22 09:52:16 +0000 (Thu, 22 Nov 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>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 <a href="http://core.trac.wordpress.org/ticket/22356">#22356</a>. see <a href="http://core.trac.wordpress.org/ticket/6821">#6821</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesimageeditphp">trunk/wp-admin/includes/image-edit.php</a></li>
<li><a href="#trunkwpadminincludesimagephp">trunk/wp-admin/includes/image.php</a></li>
<li><a href="#trunkwpadminincludesmediaphp">trunk/wp-admin/includes/media.php</a></li>
<li><a href="#trunkwpincludesclasswpimageeditorgdphp">trunk/wp-includes/class-wp-image-editor-gd.php</a></li>
<li><a href="#trunkwpincludesclasswpimageeditorimagickphp">trunk/wp-includes/class-wp-image-editor-imagick.php</a></li>
<li><a href="#trunkwpincludesclasswpimageeditorphp">trunk/wp-includes/class-wp-image-editor.php</a></li>
<li><a href="#trunkwpincludesdeprecatedphp">trunk/wp-includes/deprecated.php</a></li>
<li><a href="#trunkwpincludesmediaphp">trunk/wp-includes/media.php</a></li>
<li><a href="#trunkwpsettingsphp">trunk/wp-settings.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesimageeditphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/image-edit.php (22816 => 22817)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/image-edit.php        2012-11-22 09:32:21 UTC (rev 22816)
+++ trunk/wp-admin/includes/image-edit.php        2012-11-22 09:52:16 UTC (rev 22817)
</span><span class="lines">@@ -457,7 +457,7 @@
</span><span class="cx">         $post = get_post( $post_id );
</span><span class="cx">         @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
</span><span class="cx"> 
</span><del>-        $img = WP_Image_Editor::get_instance( _load_image_to_edit_path( $post_id ) );
</del><ins>+        $img = wp_get_image_editor( _load_image_to_edit_path( $post_id ) );
</ins><span class="cx"> 
</span><span class="cx">     if ( is_wp_error( $img ) )
</span><span class="cx">         return false;
</span><span class="lines">@@ -566,7 +566,7 @@
</span><span class="cx">         $success = $delete = $scaled = $nocrop = false;
</span><span class="cx">         $post = get_post( $post_id );
</span><span class="cx"> 
</span><del>-        $img = WP_Image_Editor::get_instance( _load_image_to_edit_path( $post_id, 'full' ) );
</del><ins>+        $img = wp_get_image_editor( _load_image_to_edit_path( $post_id, 'full' ) );
</ins><span class="cx">         if ( is_wp_error( $img ) ) {
</span><span class="cx">                 $return-&gt;error = esc_js( __('Unable to create new image.') );
</span><span class="cx">                 return $return;
</span></span></pre></div>
<a id="trunkwpadminincludesimagephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/image.php (22816 => 22817)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/image.php        2012-11-22 09:32:21 UTC (rev 22816)
+++ trunk/wp-admin/includes/image.php        2012-11-22 09:52:16 UTC (rev 22817)
</span><span class="lines">@@ -36,7 +36,7 @@
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        $editor = WP_Image_Editor::get_instance( $src );
</del><ins>+        $editor = wp_get_image_editor( $src );
</ins><span class="cx">         if ( is_wp_error( $editor ) )
</span><span class="cx">                 return $editor;
</span><span class="cx"> 
</span><span class="lines">@@ -100,7 +100,7 @@
</span><span class="cx">                 $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
</span><span class="cx"> 
</span><span class="cx">                 if ( $sizes ) {
</span><del>-                        $editor = WP_Image_Editor::get_instance( $file );
</del><ins>+                        $editor = wp_get_image_editor( $file );
</ins><span class="cx"> 
</span><span class="cx">                         if ( ! is_wp_error( $editor ) )
</span><span class="cx">                                 $metadata['sizes'] = $editor-&gt;multi_resize( $sizes );
</span></span></pre></div>
<a id="trunkwpadminincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/media.php (22816 => 22817)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/media.php        2012-11-22 09:32:21 UTC (rev 22816)
+++ trunk/wp-admin/includes/media.php        2012-11-22 09:52:16 UTC (rev 22817)
</span><span class="lines">@@ -1122,7 +1122,7 @@
</span><span class="cx">         $media_dims = apply_filters( 'media_meta', $media_dims, $post );
</span><span class="cx"> 
</span><span class="cx">         $image_edit_button = '';
</span><del>-        if ( gd_edit_image_support( $post-&gt;post_mime_type ) ) {
</del><ins>+        if ( wp_image_editor_supports( array( 'mime_type' =&gt; $post-&gt;post_mime_type ) ) ) {
</ins><span class="cx">                 $nonce = wp_create_nonce( &quot;image_editor-$post-&gt;ID&quot; );
</span><span class="cx">                 $image_edit_button = &quot;&lt;input type='button' id='imgedit-open-btn-$post-&gt;ID' onclick='imageEdit.open( $post-&gt;ID, \&quot;$nonce\&quot; )' class='button' value='&quot; . esc_attr__( 'Edit Image' ) . &quot;' /&gt; &lt;span class='spinner'&gt;&lt;/span&gt;&quot;;
</span><span class="cx">         }
</span><span class="lines">@@ -2253,7 +2253,7 @@
</span><span class="cx">         $att_url = wp_get_attachment_url( $post-&gt;ID );
</span><span class="cx"> 
</span><span class="cx">         $image_edit_button = '';
</span><del>-        if ( gd_edit_image_support( $post-&gt;post_mime_type ) ) {
</del><ins>+        if ( wp_image_editor_supports( array( 'mime_type' =&gt; $post-&gt;post_mime_type ) ) ) {
</ins><span class="cx">                 $nonce = wp_create_nonce( &quot;image_editor-$post-&gt;ID&quot; );
</span><span class="cx">                 $image_edit_button = &quot;&lt;input type='button' id='imgedit-open-btn-$post-&gt;ID' onclick='imageEdit.open( $post-&gt;ID, \&quot;$nonce\&quot; )' class='button' value='&quot; . esc_attr__( 'Edit Image' ) . &quot;' /&gt; &lt;span class='spinner'&gt;&lt;/span&gt;&quot;;
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkwpincludesclasswpimageeditorgdphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-wp-image-editor-gd.php (22816 => 22817)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-wp-image-editor-gd.php        2012-11-22 09:32:21 UTC (rev 22816)
+++ trunk/wp-includes/class-wp-image-editor-gd.php        2012-11-22 09:52:16 UTC (rev 22817)
</span><span class="lines">@@ -15,6 +15,7 @@
</span><span class="cx">  * @uses WP_Image_Editor Extends class
</span><span class="cx">  */
</span><span class="cx"> class WP_Image_Editor_GD extends WP_Image_Editor {
</span><ins>+
</ins><span class="cx">         protected $image = false; // GD Resource
</span><span class="cx"> 
</span><span class="cx">         function __destruct() {
</span><span class="lines">@@ -32,7 +33,7 @@
</span><span class="cx">          *
</span><span class="cx">          * @return boolean
</span><span class="cx">          */
</span><del>-        public static function test( $args = null ) {
</del><ins>+        public static function test( $args = array() ) {
</ins><span class="cx">                 if ( ! extension_loaded('gd') || ! function_exists('gd_info') )
</span><span class="cx">                         return false;
</span><span class="cx"> 
</span><span class="lines">@@ -40,6 +41,29 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><ins>+         * Checks to see if editor supports the mime-type specified.
+         *
+         * @since 3.5.0
+         * @access public
+         *
+         * @param string $mime_type
+         * @return boolean
+         */
+        public static function supports_mime_type( $mime_type ) {
+                $image_types = imagetypes();
+                switch( $mime_type ) {
+                        case 'image/jpeg':
+                                return ($image_types &amp; IMG_JPG) != 0;
+                        case 'image/png':
+                                return ($image_types &amp; IMG_PNG) != 0;
+                        case 'image/gif':
+                                return ($image_types &amp; IMG_GIF) != 0;
+                }
+
+                return false;
+        }
+
+        /**
</ins><span class="cx">          * Loads image from $this-&gt;file into new GD Resource.
</span><span class="cx">          *
</span><span class="cx">          * @since 3.5.0
</span><span class="lines">@@ -47,7 +71,7 @@
</span><span class="cx">          *
</span><span class="cx">          * @return boolean|\WP_Error
</span><span class="cx">          */
</span><del>-        protected function load() {
</del><ins>+        public function load() {
</ins><span class="cx">                 if ( $this-&gt;image )
</span><span class="cx">                         return true;
</span><span class="cx"> 
</span><span class="lines">@@ -91,21 +115,6 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><del>-         * Checks to see if editor supports the mime-type specified.
-         *
-         * @since 3.5.0
-         * @access public
-         *
-         * @param string $mime_type
-         * @return boolean
-         */
-        public static function supports_mime_type( $mime_type ) {
-                $allowed_mime_types = array( 'image/gif', 'image/png', 'image/jpeg' );
-
-                return in_array( $mime_type, $allowed_mime_types );
-        }
-
-        /**
</del><span class="cx">          * Resizes current image.
</span><span class="cx">          * Wraps _resize, since _resize returns a GD Resource.
</span><span class="cx">          *
</span><span class="lines">@@ -261,7 +270,7 @@
</span><span class="cx">          * @since 3.5.0
</span><span class="cx">          * @access public
</span><span class="cx">          *
</span><del>-         * @param boolean $horz Horizonal Flip
</del><ins>+         * @param boolean $horz Horizontal Flip
</ins><span class="cx">          * @param boolean $vert Vertical Flip
</span><span class="cx">          * @returns boolean|WP_Error
</span><span class="cx">          */
</span><span class="lines">@@ -369,4 +378,4 @@
</span><span class="cx">                                 return imagejpeg( $this-&gt;image, null, $this-&gt;quality );
</span><span class="cx">                 }
</span><span class="cx">         }
</span><del>-}
</del><span class="cx">\ No newline at end of file
</span><ins>+}
</ins></span></pre></div>
<a id="trunkwpincludesclasswpimageeditorimagickphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-wp-image-editor-imagick.php (22816 => 22817)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-wp-image-editor-imagick.php        2012-11-22 09:32:21 UTC (rev 22816)
+++ trunk/wp-includes/class-wp-image-editor-imagick.php        2012-11-22 09:52:16 UTC (rev 22817)
</span><span class="lines">@@ -15,6 +15,7 @@
</span><span class="cx">  * @uses WP_Image_Editor Extends class
</span><span class="cx">  */
</span><span class="cx"> class WP_Image_Editor_Imagick extends WP_Image_Editor {
</span><ins>+
</ins><span class="cx">         protected $image = null; // Imagick Object
</span><span class="cx"> 
</span><span class="cx">         function __destruct() {
</span><span class="lines">@@ -36,7 +37,7 @@
</span><span class="cx">          *
</span><span class="cx">          * @return boolean
</span><span class="cx">          */
</span><del>-        public static function test( $args = null ) {
</del><ins>+        public static function test( $args = array() ) {
</ins><span class="cx">                 if ( ! extension_loaded( 'imagick' ) || ! is_callable( 'Imagick', 'queryFormats' ) )
</span><span class="cx">                         return false;
</span><span class="cx"> 
</span><span class="lines">@@ -44,6 +45,29 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><ins>+         * Checks to see if editor supports the mime-type specified.
+         *
+         * @since 3.5.0
+         * @access public
+         *
+         * @param string $mime_type
+         * @return boolean
+         */
+        public static function supports_mime_type( $mime_type ) {
+                $imagick_extension = strtoupper( self::get_extension( $mime_type ) );
+
+                if ( ! $imagick_extension )
+                        return false;
+
+                try {
+                        return ( (bool) Imagick::queryFormats( $imagick_extension ) );
+                }
+                catch ( Exception $e ) {
+                        return false;
+                }
+        }
+
+        /**
</ins><span class="cx">          * Loads image from $this-&gt;file into new Imagick Object.
</span><span class="cx">          *
</span><span class="cx">          * @since 3.5.0
</span><span class="lines">@@ -51,7 +75,7 @@
</span><span class="cx">          *
</span><span class="cx">          * @return boolean|WP_Error True if loaded; WP_Error on failure.
</span><span class="cx">          */
</span><del>-        protected function load() {
</del><ins>+        public function load() {
</ins><span class="cx">                 if ( $this-&gt;image )
</span><span class="cx">                         return true;
</span><span class="cx"> 
</span><span class="lines">@@ -138,29 +162,6 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><del>-         * Checks to see if editor supports the mime-type specified.
-         *
-         * @since 3.5.0
-         * @access public
-         *
-         * @param string $mime_type
-         * @return boolean
-         */
-        public static function supports_mime_type( $mime_type ) {
-                if ( ! $mime_type )
-                        return false;
-
-                $imagick_extension = strtoupper( self::get_extension( $mime_type ) );
-
-                try {
-                        return ( (bool) Imagick::queryFormats( $imagick_extension ) );
-                }
-                catch ( Exception $e ) {
-                        return false;
-                }
-        }
-
-        /**
</del><span class="cx">          * Resizes current image.
</span><span class="cx">          *
</span><span class="cx">          * @since 3.5.0
</span><span class="lines">@@ -312,7 +313,7 @@
</span><span class="cx">          * @since 3.5.0
</span><span class="cx">          * @access public
</span><span class="cx">          *
</span><del>-         * @param boolean $horz Horizonal Flip
</del><ins>+         * @param boolean $horz Horizontal Flip
</ins><span class="cx">          * @param boolean $vert Vertical Flip
</span><span class="cx">          * @returns boolean|WP_Error
</span><span class="cx">          */
</span></span></pre></div>
<a id="trunkwpincludesclasswpimageeditorphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-wp-image-editor.php (22816 => 22817)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-wp-image-editor.php        2012-11-22 09:32:21 UTC (rev 22816)
+++ trunk/wp-includes/class-wp-image-editor.php        2012-11-22 09:52:16 UTC (rev 22817)
</span><span class="lines">@@ -7,75 +7,51 @@
</span><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Base WordPress Image Editor class for which Editor implementations extend
</del><ins>+ * Base image editor class from which implementations extend
</ins><span class="cx">  *
</span><span class="cx">  * @since 3.5.0
</span><span class="cx">  */
</span><span class="cx"> abstract class WP_Image_Editor {
</span><span class="cx">         protected $file = null;
</span><span class="cx">         protected $size = null;
</span><del>-        protected $mime_type  = null;
</del><ins>+        protected $mime_type = null;
</ins><span class="cx">         protected $default_mime_type = 'image/jpeg';
</span><span class="cx">         protected $quality = 90;
</span><span class="cx"> 
</span><del>-        protected function __construct( $filename ) {
-                $this-&gt;file = $filename;
</del><ins>+        /**
+         * Each instance handles a single file.
+         */
+        public function __construct( $file ) {
+                $this-&gt;file = $file;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><del>-         * Returns a WP_Image_Editor instance and loads file into it.
</del><ins>+         * Checks to see if current environment supports the editor chosen.
+         * Must be overridden in a sub-class.
</ins><span class="cx">          *
</span><span class="cx">          * @since 3.5.0
</span><span class="cx">          * @access public
</span><ins>+         * @abstract
</ins><span class="cx">          *
</span><del>-         * @param string $path Path to File to Load
-         * @param array $required_methods Methods to require in implementation
-         * @return WP_Image_Editor|WP_Error
</del><ins>+         * @param array $args
+         * @return boolean
</ins><span class="cx">          */
</span><del>-        public final static function get_instance( $path = null, $required_methods = null ) {
-                $implementation = apply_filters( 'wp_image_editor_class', self::choose_implementation( $required_methods ), $path );
-
-                if ( $implementation ) {
-                        $editor = new $implementation( $path );
-                        $loaded = $editor-&gt;load();
-
-                        if ( is_wp_error( $loaded ) )
-                                return $loaded;
-
-                        return $editor;
-                }
-
-                return new WP_Error( 'no_editor', __('No editor could be selected') );
</del><ins>+        public static function test( $args = array() ) {
+                return false;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><del>-         * Tests which editors are capable of supporting the request.
</del><ins>+         * Checks to see if editor supports the mime-type specified.
+         * Must be overridden in a sub-class.
</ins><span class="cx">          *
</span><span class="cx">          * @since 3.5.0
</span><del>-         * @access private
</del><ins>+         * @access public
+         * @abstract
</ins><span class="cx">          *
</span><del>-         * @param array $required_methods String array of all methods required for implementation returned.
-         * @return string|bool Class name for the first editor that claims to support the request. False if no editor claims to support the request.
</del><ins>+         * @param string $mime_type
+         * @return boolean
</ins><span class="cx">          */
</span><del>-        private final static function choose_implementation( $required_methods = null ) {
-                $request_order = apply_filters( 'wp_image_editors',
-                        array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) );
-
-                if ( ! $required_methods )
-                        $required_methods = array();
-
-                // Loop over each editor on each request looking for one which will serve this request's needs
-                foreach ( $request_order as $editor ) {
-                        // Check to see if this editor is a possibility, calls the editor statically
-                        if ( ! call_user_func( array( $editor, 'test' ) ) )
-                                continue;
-
-                        // Make sure that all methods are supported by editor.
-                        if ( array_diff( $required_methods, get_class_methods( $editor ) ) )
-                                continue;
-
-                        return $editor;
-                }
</del><ins>+        public static function supports_mime_type( $mime_type ) {
</ins><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -88,7 +64,7 @@
</span><span class="cx">          *
</span><span class="cx">          * @return boolean|WP_Error True if loaded; WP_Error on failure.
</span><span class="cx">          */
</span><del>-        abstract protected function load();
</del><ins>+        abstract public function load();
</ins><span class="cx"> 
</span><span class="cx">         /**
</span><span class="cx">          * Saves current image to file.
</span><span class="lines">@@ -168,7 +144,7 @@
</span><span class="cx">          * @access public
</span><span class="cx">          * @abstract
</span><span class="cx">          *
</span><del>-         * @param boolean $horz Horizonal Flip
</del><ins>+         * @param boolean $horz Horizontal Flip
</ins><span class="cx">          * @param boolean $vert Vertical Flip
</span><span class="cx">          * @return boolean|WP_Error
</span><span class="cx">          */
</span><span class="lines">@@ -187,36 +163,6 @@
</span><span class="cx">         abstract public function stream( $mime_type = null );
</span><span class="cx"> 
</span><span class="cx">         /**
</span><del>-         * Checks to see if current environment supports the editor chosen.
-         * Must be overridden in a sub-class.
-         *
-         * @since 3.5.0
-         * @access public
-         * @abstract
-         *
-         * @param array $args
-         * @return boolean
-         */
-        public static function test( $args = null ) {
-                return false;
-        }
-
-        /**
-         * Checks to see if editor supports the mime-type specified.
-         * Must be overridden in a sub-class.
-         *
-         * @since 3.5.0
-         * @access public
-         * @abstract
-         *
-         * @param string $mime_type
-         * @return boolean
-         */
-        public static function supports_mime_type( $mime_type ) {
-                return false;
-        }
-
-        /**
</del><span class="cx">          * Gets dimensions of image.
</span><span class="cx">          *
</span><span class="cx">          * @since 3.5.0
</span><span class="lines">@@ -451,3 +397,4 @@
</span><span class="cx">                 return $extensions[0];
</span><span class="cx">         }
</span><span class="cx"> }
</span><ins>+
</ins></span></pre></div>
<a id="trunkwpincludesdeprecatedphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/deprecated.php (22816 => 22817)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/deprecated.php        2012-11-22 09:32:21 UTC (rev 22816)
+++ trunk/wp-includes/deprecated.php        2012-11-22 09:52:16 UTC (rev 22817)
</span><span class="lines">@@ -3210,13 +3210,13 @@
</span><span class="cx">  *
</span><span class="cx">  * @since 2.1.0
</span><span class="cx">  * @deprecated 3.5.0
</span><del>- * @see WP_Image_Editor
</del><ins>+ * @see wp_get_image_editor()
</ins><span class="cx">  *
</span><span class="cx">  * @param string $file Filename of the image to load.
</span><span class="cx">  * @return resource The resulting image resource on success, Error string on failure.
</span><span class="cx">  */
</span><span class="cx"> function wp_load_image( $file ) {
</span><del>-        _deprecated_function( __FUNCTION__, '3.5', 'WP_Image_Editor' );
</del><ins>+        _deprecated_function( __FUNCTION__, '3.5', 'wp_get_image_editor()' );
</ins><span class="cx"> 
</span><span class="cx">         if ( is_numeric( $file ) )
</span><span class="cx">                 $file = get_attached_file( $file );
</span><span class="lines">@@ -3250,7 +3250,7 @@
</span><span class="cx">  *
</span><span class="cx">  * @since 2.5.0
</span><span class="cx">  * @deprecated 3.5.0
</span><del>- * @see WP_Image_Editor
</del><ins>+ * @see wp_get_image_editor()
</ins><span class="cx">  *
</span><span class="cx">  * @param string $file Image file path.
</span><span class="cx">  * @param int $max_w Maximum width to resize to.
</span><span class="lines">@@ -3262,9 +3262,9 @@
</span><span class="cx">  * @return mixed WP_Error on failure. String with new destination path.
</span><span class="cx">  */
</span><span class="cx"> function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
</span><del>-        _deprecated_function( __FUNCTION__, '3.5', 'WP_Image_Editor' );
</del><ins>+        _deprecated_function( __FUNCTION__, '3.5', 'wp_get_image_editor()' );
</ins><span class="cx"> 
</span><del>-        $editor = WP_Image_Editor::get_instance( $file );
</del><ins>+        $editor = wp_get_image_editor( $file );
</ins><span class="cx">         if ( is_wp_error( $editor ) )
</span><span class="cx">                 return $editor;
</span><span class="cx">         $editor-&gt;set_quality( $jpeg_quality );
</span><span class="lines">@@ -3328,4 +3328,39 @@
</span><span class="cx">  * @since 2.3.0
</span><span class="cx">  * @deprecated 3.5.0
</span><span class="cx">  */
</span><del>-function _save_post_hook() {}
</del><span class="cx">\ No newline at end of file
</span><ins>+function _save_post_hook() {}
+
+/**
+ * Check if the installed version of GD supports particular image type
+ *
+ * @since 2.9.0
+ * @deprecated 3.5.0
+ * see wp_image_editor_supports()
+ *
+ * @param string $mime_type
+ * @return bool
+ */
+function gd_edit_image_support($mime_type) {
+        _deprecated_function( __FUNCTION__, '3.5', 'wp_image_editor_supports()' );
+
+        if ( function_exists('imagetypes') ) {
+                switch( $mime_type ) {
+                        case 'image/jpeg':
+                                return (imagetypes() &amp; IMG_JPG) != 0;
+                        case 'image/png':
+                                return (imagetypes() &amp; IMG_PNG) != 0;
+                        case 'image/gif':
+                                return (imagetypes() &amp; IMG_GIF) != 0;
+                }
+        } else {
+                switch( $mime_type ) {
+                        case 'image/jpeg':
+                                return function_exists('imagecreatefromjpeg');
+                        case 'image/png':
+                                return function_exists('imagecreatefrompng');
+                        case 'image/gif':
+                                return function_exists('imagecreatefromgif');
+                }
+        }
+        return false;
+}
</ins></span></pre></div>
<a id="trunkwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/media.php (22816 => 22817)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2012-11-22 09:32:21 UTC (rev 22816)
+++ trunk/wp-includes/media.php        2012-11-22 09:52:16 UTC (rev 22817)
</span><span class="lines">@@ -383,7 +383,7 @@
</span><span class="cx">  */
</span><span class="cx"> function image_make_intermediate_size( $file, $width, $height, $crop = false ) {
</span><span class="cx">         if ( $width || $height ) {
</span><del>-                $editor = WP_Image_Editor::get_instance( $file );
</del><ins>+                $editor = wp_get_image_editor( $file );
</ins><span class="cx"> 
</span><span class="cx">                 if ( is_wp_error( $editor ) || is_wp_error( $editor-&gt;resize( $width, $height, $crop ) ) )
</span><span class="cx">                         return false;
</span><span class="lines">@@ -904,37 +904,6 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * Check if the installed version of GD supports particular image type
- *
- * @since 2.9.0
- *
- * @param string $mime_type
- * @return bool
- */
-function gd_edit_image_support($mime_type) {
-        if ( function_exists('imagetypes') ) {
-                switch( $mime_type ) {
-                        case 'image/jpeg':
-                                return (imagetypes() &amp; IMG_JPG) != 0;
-                        case 'image/png':
-                                return (imagetypes() &amp; IMG_PNG) != 0;
-                        case 'image/gif':
-                                return (imagetypes() &amp; IMG_GIF) != 0;
-                }
-        } else {
-                switch( $mime_type ) {
-                        case 'image/jpeg':
-                                return function_exists('imagecreatefromjpeg');
-                        case 'image/png':
-                                return function_exists('imagecreatefrompng');
-                        case 'image/gif':
-                                return function_exists('imagecreatefromgif');
-                }
-        }
-        return false;
-}
-
-/**
</del><span class="cx">  * Create new GD image resource with transparency support
</span><span class="cx">  * @TODO: Deprecate if possible.
</span><span class="cx">  *
</span><span class="lines">@@ -1171,6 +1140,95 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Returns a WP_Image_Editor instance and loads file into it.
+ *
+ * @since 3.5.0
+ * @access public
+ *
+ * @param string $path Path to file to load
+ * @param array $args Additional data. Accepts { 'mime_type'=&gt;string, 'methods'=&gt;{string, string, ...} }
+ * @return WP_Image_Editor|WP_Error
+ */
+function wp_get_image_editor( $path, $args = array() ) {
+        $args['path'] = $path;
+
+        if ( ! isset( $args['mime_type'] ) ) {
+                $file_info  = wp_check_filetype( $args['path'] );
+
+                // If $file_info['type'] is false, then we let the editor attempt to
+                // figure out the file type, rather than forcing a failure based on extension.
+                if ( isset( $file_info ) &amp;&amp; $file_info['type'] )
+                        $args['mime_type'] = $file_info['type'];
+        }
+
+        $implementation = apply_filters( 'wp_image_editor_class', _wp_image_editor_choose( $args ) );
+
+        if ( $implementation ) {
+                $editor = new $implementation( $path );
+                $loaded = $editor-&gt;load();
+
+                if ( is_wp_error( $loaded ) )
+                        return $loaded;
+
+                return $editor;
+        }
+
+        return new WP_Error( 'image_no_editor', __('No editor could be selected.') );
+}
+
+/**
+ * Tests whether there is an editor that supports a given mime type or methods.
+ *
+ * @since 3.5.0
+ * @access public
+ *
+ * @param string|array $args Array of requirements.  Accepts { 'mime_type'=&gt;string, 'methods'=&gt;{string, string, ...} }
+ * @return boolean true if an eligible editor is found; false otherwise
+ */
+function wp_image_editor_supports( $args = array() ) {
+        return (bool) _wp_image_editor_choose( $args );
+}
+
+/**
+ * Tests which editors are capable of supporting the request.
+ *
+ * @since 3.5.0
+ * @access private
+ *
+ * @param array $args Additional data. Accepts { 'mime_type'=&gt;string, 'methods'=&gt;{string, string, ...} }
+ * @return string|bool Class name for the first editor that claims to support the request. False if no editor claims to support the request.
+ */
+function _wp_image_editor_choose( $args = array() ) {
+        require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
+        require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php';
+        require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php';
+
+        $implementations = apply_filters( 'wp_image_editors',
+                array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) );
+
+        foreach ( $implementations as $implementation ) {
+                if ( ! call_user_func( array( $implementation, 'test' ), $args ) )
+                        continue;
+
+                if ( isset( $args['mime_type'] ) &amp;&amp;
+                        ! call_user_func(
+                                array( $implementation, 'supports_mime_type' ),
+                                $args['mime_type'] ) ) {
+                        continue;
+                }
+
+                if ( isset( $args['methods'] ) &amp;&amp;
+                         array_diff( $args['methods'], get_class_methods( $implementation ) ) ) {
+                        continue;
+                }
+
+                return $implementation;
+        }
+
+        return false;
+}
+
+/**
</ins><span class="cx">  * Prints default plupload arguments.
</span><span class="cx">  *
</span><span class="cx">  * @since 3.4.0
</span></span></pre></div>
<a id="trunkwpsettingsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-settings.php (22816 => 22817)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-settings.php        2012-11-22 09:32:21 UTC (rev 22816)
+++ trunk/wp-settings.php        2012-11-22 09:52:16 UTC (rev 22817)
</span><span class="lines">@@ -143,10 +143,6 @@
</span><span class="cx"> require( ABSPATH . WPINC . '/nav-menu-template.php' );
</span><span class="cx"> require( ABSPATH . WPINC . '/admin-bar.php' );
</span><span class="cx"> 
</span><del>-require( ABSPATH . WPINC . '/class-wp-image-editor.php' );
-require( ABSPATH . WPINC . '/class-wp-image-editor-gd.php' );
-require( ABSPATH . WPINC . '/class-wp-image-editor-imagick.php' );
-
</del><span class="cx"> // Load multisite-specific files.
</span><span class="cx"> if ( is_multisite() ) {
</span><span class="cx">         require( ABSPATH . WPINC . '/ms-functions.php' );
</span></span></pre>
</div>
</div>

</body>
</html>