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.



git-svn-id: https://develop.svn.wordpress.org/trunk@22817 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin
2012-11-22 09:52:16 +00:00
parent ff6ae18d2d
commit f44d1d009e
9 changed files with 216 additions and 170 deletions
+41 -6
View File
@@ -3210,13 +3210,13 @@ function _get_post_ancestors( &$post ) {
*
* @since 2.1.0
* @deprecated 3.5.0
* @see WP_Image_Editor
* @see wp_get_image_editor()
*
* @param string $file Filename of the image to load.
* @return resource The resulting image resource on success, Error string on failure.
*/
function wp_load_image( $file ) {
_deprecated_function( __FUNCTION__, '3.5', 'WP_Image_Editor' );
_deprecated_function( __FUNCTION__, '3.5', 'wp_get_image_editor()' );
if ( is_numeric( $file ) )
$file = get_attached_file( $file );
@@ -3250,7 +3250,7 @@ function wp_load_image( $file ) {
*
* @since 2.5.0
* @deprecated 3.5.0
* @see WP_Image_Editor
* @see wp_get_image_editor()
*
* @param string $file Image file path.
* @param int $max_w Maximum width to resize to.
@@ -3262,9 +3262,9 @@ function wp_load_image( $file ) {
* @return mixed WP_Error on failure. String with new destination path.
*/
function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
_deprecated_function( __FUNCTION__, '3.5', 'WP_Image_Editor' );
_deprecated_function( __FUNCTION__, '3.5', 'wp_get_image_editor()' );
$editor = WP_Image_Editor::get_instance( $file );
$editor = wp_get_image_editor( $file );
if ( is_wp_error( $editor ) )
return $editor;
$editor->set_quality( $jpeg_quality );
@@ -3328,4 +3328,39 @@ function user_pass_ok($user_login, $user_pass) {
* @since 2.3.0
* @deprecated 3.5.0
*/
function _save_post_hook() {}
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() & IMG_JPG) != 0;
case 'image/png':
return (imagetypes() & IMG_PNG) != 0;
case 'image/gif':
return (imagetypes() & 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;
}