diff --git wp-admin/includes/image-edit.php wp-admin/includes/image-edit.php
index 0b06926..a1e429f 100644
|
|
|
function wp_stream_image( $image, $mime_type, $post_id ) { |
| 237 | 237 | |
| 238 | 238 | /** |
| 239 | 239 | * Saves Image to File |
| 240 | | * @TODO: Add mime_type support to WP_Image_Editor |
| 241 | 240 | * |
| 242 | 241 | * @param string $filename |
| 243 | 242 | * @param WP_Image_Editor $image |
diff --git wp-includes/class-wp-image-editor-gd.php wp-includes/class-wp-image-editor-gd.php
index 9248c7e..dcd1644 100644
|
|
|
class WP_Image_Editor_GD extends WP_Image_Editor { |
| 28 | 28 | * Checks to see if current environment supports GD |
| 29 | 29 | * |
| 30 | 30 | * @since 3.5.0 |
| 31 | | * @access protected |
| | 31 | * @access public |
| 32 | 32 | * |
| 33 | 33 | * @return boolean |
| 34 | 34 | */ |
| 35 | | public function test() { |
| | 35 | public static function test( $args = null ) { |
| 36 | 36 | if ( ! extension_loaded('gd') || ! function_exists('gd_info') ) |
| 37 | 37 | return false; |
| 38 | 38 | |
| … |
… |
class WP_Image_Editor_GD extends WP_Image_Editor { |
| 51 | 51 | if ( $this->image ) |
| 52 | 52 | return true; |
| 53 | 53 | |
| 54 | | if ( ! file_exists( $this->file ) ) |
| | 54 | if ( ! is_file( $this->file ) ) |
| 55 | 55 | return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file ); |
| 56 | 56 | |
| 57 | 57 | // Set artificially high because GD uses uncompressed images in memory |
| … |
… |
class WP_Image_Editor_GD extends WP_Image_Editor { |
| 99 | 99 | * @param string $mime_type |
| 100 | 100 | * @return boolean |
| 101 | 101 | */ |
| 102 | | public function supports_mime_type( $mime_type ) { |
| | 102 | public static function supports_mime_type( $mime_type ) { |
| 103 | 103 | $allowed_mime_types = array( 'image/gif', 'image/png', 'image/jpeg' ); |
| 104 | 104 | |
| 105 | 105 | return in_array( $mime_type, $allowed_mime_types ); |
diff --git wp-includes/class-wp-image-editor-imagick.php wp-includes/class-wp-image-editor-imagick.php
index 9d2c822..c3372d3 100644
|
|
|
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
| 29 | 29 | * Checks to see if current environment supports Imagick |
| 30 | 30 | * |
| 31 | 31 | * @since 3.5.0 |
| 32 | | * @access protected |
| | 32 | * @access public |
| 33 | 33 | * |
| 34 | 34 | * @return boolean |
| 35 | 35 | */ |
| 36 | | public function test() { |
| | 36 | public static function test( $args = null ) { |
| 37 | 37 | if ( ! extension_loaded( 'imagick' ) ) |
| 38 | 38 | return false; |
| 39 | 39 | |
| … |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
| 52 | 52 | if ( $this->image ) |
| 53 | 53 | return true; |
| 54 | 54 | |
| 55 | | if ( ! file_exists( $this->file ) ) |
| | 55 | if ( ! is_file( $this->file ) ) |
| 56 | 56 | return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file ); |
| 57 | 57 | |
| 58 | 58 | try { |
| … |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
| 143 | 143 | * @param string $mime_type |
| 144 | 144 | * @return boolean |
| 145 | 145 | */ |
| 146 | | public function supports_mime_type( $mime_type ) { |
| | 146 | public static function supports_mime_type( $mime_type ) { |
| 147 | 147 | if ( ! $mime_type ) |
| 148 | 148 | return false; |
| 149 | 149 | |
diff --git wp-includes/class-wp-image-editor.php wp-includes/class-wp-image-editor.php
index 6ee94a2..05665b6 100644
|
|
|
abstract class WP_Image_Editor { |
| 17 | 17 | protected $mime_type = null; |
| 18 | 18 | protected $default_mime_type = 'image/jpeg'; |
| 19 | 19 | protected $quality = 90; |
| 20 | | private static $implementation; |
| 21 | 20 | |
| 22 | 21 | protected function __construct( $filename ) { |
| 23 | 22 | $this->file = $filename; |
| … |
… |
abstract class WP_Image_Editor { |
| 30 | 29 | * @access public |
| 31 | 30 | * |
| 32 | 31 | * @param string $path Path to File to Load |
| | 32 | * @param array $required_methods Methods to require in implementation |
| 33 | 33 | * @return WP_Image_Editor|WP_Error|boolean |
| 34 | 34 | */ |
| 35 | | public final static function get_instance( $path = null ) { |
| 36 | | $implementation = apply_filters( 'image_editor_class', self::choose_implementation(), $path ); |
| | 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 | 37 | |
| 38 | 38 | if ( $implementation ) { |
| 39 | 39 | $editor = new $implementation( $path ); |
| 40 | 40 | $loaded = $editor->load(); |
| 41 | 41 | |
| 42 | | if ( is_wp_error ( $loaded ) ) |
| | 42 | if ( is_wp_error( $loaded ) ) |
| 43 | 43 | return $loaded; |
| 44 | 44 | |
| 45 | 45 | return $editor; |
| … |
… |
abstract class WP_Image_Editor { |
| 54 | 54 | * @since 3.5.0 |
| 55 | 55 | * @access private |
| 56 | 56 | * |
| | 57 | * @param $required_methods Array String array of all methods required for implementation returned. |
| | 58 | * |
| 57 | 59 | * @return string|bool Class name for the first editor that claims to support the request. False if no editor claims to support the request. |
| 58 | 60 | */ |
| 59 | | private final static function choose_implementation() { |
| | 61 | private final static function choose_implementation( $required_methods = null ) { |
| | 62 | $request_order = apply_filters( 'wp_image_editors', |
| | 63 | array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) ); |
| 60 | 64 | |
| 61 | | if ( null === self::$implementation ) { |
| 62 | | $request_order = apply_filters( 'wp_editors', array( 'imagick', 'gd' ) ); |
| | 65 | if ( ! $required_methods ) |
| | 66 | $required_methods = apply_filters( 'wp_image_editor_default_methods', |
| | 67 | array( 'resize', 'multi_resize', 'crop', 'rotate', 'flip', 'stream' ) ); |
| 63 | 68 | |
| 64 | | // Loop over each editor on each request looking for one which will serve this request's needs |
| 65 | | foreach ( $request_order as $editor ) { |
| 66 | | $class = 'WP_Image_Editor_' . $editor; |
| | 69 | // Loop over each editor on each request looking for one which will serve this request's needs |
| | 70 | foreach ( $request_order as $editor ) { |
| | 71 | // Check to see if this editor is a possibility, calls the editor statically |
| | 72 | if ( ! call_user_func( array( $editor, 'test' ) ) ) |
| | 73 | continue; |
| 67 | 74 | |
| 68 | | // Check to see if this editor is a possibility, calls the editor statically |
| 69 | | if ( ! call_user_func( array( $class, 'test' ) ) ) |
| 70 | | continue; |
| | 75 | // Make sure that all methods are supported by editor. |
| | 76 | if ( array_diff( $required_methods, get_class_methods( $editor ) ) ) |
| | 77 | continue; |
| 71 | 78 | |
| 72 | | self::$implementation = $class; |
| 73 | | break; |
| 74 | | } |
| | 79 | return $editor; |
| 75 | 80 | } |
| 76 | | return self::$implementation; |
| | 81 | return false; |
| 77 | 82 | } |
| 78 | 83 | |
| 79 | | abstract public function test(); // returns bool |
| 80 | 84 | abstract protected function load(); // returns bool|WP_Error |
| 81 | | abstract public function supports_mime_type( $mime_type ); // returns bool |
| 82 | | abstract public function resize( $max_w, $max_h, $crop = false ); |
| 83 | | abstract public function multi_resize( $sizes ); |
| 84 | | abstract public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ); |
| 85 | | abstract public function rotate( $angle ); |
| 86 | | abstract public function flip( $horz, $vert ); |
| 87 | 85 | abstract public function save( $destfilename = null, $mime_type = null ); |
| 88 | | abstract public function stream( $mime_type = null ); |
| | 86 | |
| | 87 | /** |
| | 88 | * Implement all of the below to support natively used functions: |
| | 89 | * |
| | 90 | * public function resize( $max_w, $max_h, $crop = false ) |
| | 91 | * public function multi_resize( $sizes ) |
| | 92 | * public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) |
| | 93 | * public function rotate( $angle ) |
| | 94 | * public function flip( $horz, $vert ) |
| | 95 | * public function stream( $mime_type = null ) |
| | 96 | */ |
| | 97 | |
| | 98 | /** |
| | 99 | * Checks to see if current environment supports the editor chosen. |
| | 100 | * Must be overridden in a sub-class. |
| | 101 | * |
| | 102 | * @since 3.5.0 |
| | 103 | * @access public |
| | 104 | * @abstract |
| | 105 | * |
| | 106 | * @param $args array |
| | 107 | * @return boolean |
| | 108 | */ |
| | 109 | public static function test( $args = null ) { |
| | 110 | return false; |
| | 111 | } |
| | 112 | |
| | 113 | /** |
| | 114 | * Checks to see if editor supports mime-type specified |
| | 115 | * Must be overridden in a sub-class. |
| | 116 | * |
| | 117 | * @since 3.5.0 |
| | 118 | * @access public |
| | 119 | * @abstract |
| | 120 | * |
| | 121 | * @param string $mime_type |
| | 122 | * @return boolean |
| | 123 | */ |
| | 124 | public static function supports_mime_type( $mime_type ) { |
| | 125 | return false; |
| | 126 | } |
| 89 | 127 | |
| 90 | 128 | /** |
| 91 | 129 | * Gets dimensions of image |
| … |
… |
abstract class WP_Image_Editor { |
| 258 | 296 | |
| 259 | 297 | $result = call_user_func_array( $function, $arguments ); |
| 260 | 298 | |
| 261 | | if( $result && $stream ) { |
| | 299 | if ( $result && $stream ) { |
| 262 | 300 | $contents = ob_get_contents(); |
| 263 | 301 | |
| 264 | 302 | $fp = fopen( $dst_file, 'w' ); |
| 265 | 303 | |
| 266 | | if( ! $fp ) |
| | 304 | if ( ! $fp ) |
| 267 | 305 | return false; |
| 268 | 306 | |
| 269 | 307 | fwrite( $fp, $contents ); |
| 270 | 308 | fclose( $fp ); |
| 271 | 309 | } |
| 272 | 310 | |
| 273 | | if( $stream ) { |
| | 311 | if ( $stream ) { |
| 274 | 312 | ob_end_clean(); |
| 275 | 313 | } |
| 276 | 314 | |
| … |
… |
abstract class WP_Image_Editor { |
| 295 | 333 | $extensions = array_keys( $mime_types ); |
| 296 | 334 | |
| 297 | 335 | foreach( $extensions as $_extension ) { |
| 298 | | if( preg_match("/{$extension}/i", $_extension ) ) { |
| 299 | | return $mime_types[ $_extension ]; |
| | 336 | if ( preg_match( "/{$extension}/i", $_extension ) ) { |
| | 337 | return $mime_types[$_extension]; |
| 300 | 338 | } |
| 301 | 339 | } |
| 302 | 340 | |
diff --git wp-includes/deprecated.php wp-includes/deprecated.php
index a9744e8..101bc10 100644
|
|
|
function wp_load_image( $file ) { |
| 3221 | 3221 | if ( is_numeric( $file ) ) |
| 3222 | 3222 | $file = get_attached_file( $file ); |
| 3223 | 3223 | |
| 3224 | | if ( ! file_exists( $file ) ) |
| | 3224 | if ( ! is_file( $file ) ) |
| 3225 | 3225 | return sprintf(__('File “%s” doesn’t exist?'), $file); |
| 3226 | 3226 | |
| 3227 | 3227 | if ( ! function_exists('imagecreatefromstring') ) |