75 * Saves current image to file. |
75 * Saves current image to file. |
76 * |
76 * |
77 * @since 3.5.0 |
77 * @since 3.5.0 |
78 * @abstract |
78 * @abstract |
79 * |
79 * |
80 * @param string $destfilename |
80 * @param string $destfilename Optional. Destination filename. Default null. |
81 * @param string $mime_type |
81 * @param string $mime_type Optional. The mime-type. Default null. |
82 * @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string} |
82 * @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string} |
83 */ |
83 */ |
84 abstract public function save( $destfilename = null, $mime_type = null ); |
84 abstract public function save( $destfilename = null, $mime_type = null ); |
85 |
85 |
86 /** |
86 /** |
107 * @abstract |
107 * @abstract |
108 * |
108 * |
109 * @param array $sizes { |
109 * @param array $sizes { |
110 * An array of image size arrays. Default sizes are 'small', 'medium', 'large'. |
110 * An array of image size arrays. Default sizes are 'small', 'medium', 'large'. |
111 * |
111 * |
112 * @type array $size { |
112 * @type array ...$0 { |
113 * @type int $width Image width. |
113 * @type int $width Image width. |
114 * @type int $height Image height. |
114 * @type int $height Image height. |
115 * @type bool $crop Optional. Whether to crop the image. Default false. |
115 * @type bool $crop Optional. Whether to crop the image. Default false. |
116 * } |
116 * } |
117 * } |
117 * } |
361 * |
361 * |
362 * @type string ...$0 The new mime type. |
362 * @type string ...$0 The new mime type. |
363 * } |
363 * } |
364 * @param string $filename Path to the image. |
364 * @param string $filename Path to the image. |
365 * @param string $mime_type The source image mime type. |
365 * @param string $mime_type The source image mime type. |
366 * } |
|
367 */ |
366 */ |
368 $output_format = apply_filters( 'image_editor_output_format', array(), $filename, $mime_type ); |
367 $output_format = apply_filters( 'image_editor_output_format', array(), $filename, $mime_type ); |
369 |
368 |
370 if ( isset( $output_format[ $mime_type ] ) |
369 if ( isset( $output_format[ $mime_type ] ) |
371 && $this->supports_mime_type( $output_format[ $mime_type ] ) |
370 && $this->supports_mime_type( $output_format[ $mime_type ] ) |
547 /** |
546 /** |
548 * Either calls editor's save function or handles file as a stream. |
547 * Either calls editor's save function or handles file as a stream. |
549 * |
548 * |
550 * @since 3.5.0 |
549 * @since 3.5.0 |
551 * |
550 * |
552 * @param string|stream $filename |
551 * @param string $filename |
553 * @param callable $function |
552 * @param callable $callback |
554 * @param array $arguments |
553 * @param array $arguments |
555 * @return bool |
554 * @return bool |
556 */ |
555 */ |
557 protected function make_image( $filename, $function, $arguments ) { |
556 protected function make_image( $filename, $callback, $arguments ) { |
558 $stream = wp_is_stream( $filename ); |
557 $stream = wp_is_stream( $filename ); |
559 if ( $stream ) { |
558 if ( $stream ) { |
560 ob_start(); |
559 ob_start(); |
561 } else { |
560 } else { |
562 // The directory containing the original file may no longer exist when using a replication plugin. |
561 // The directory containing the original file may no longer exist when using a replication plugin. |
563 wp_mkdir_p( dirname( $filename ) ); |
562 wp_mkdir_p( dirname( $filename ) ); |
564 } |
563 } |
565 |
564 |
566 $result = call_user_func_array( $function, $arguments ); |
565 $result = call_user_func_array( $callback, $arguments ); |
567 |
566 |
568 if ( $result && $stream ) { |
567 if ( $result && $stream ) { |
569 $contents = ob_get_contents(); |
568 $contents = ob_get_contents(); |
570 |
569 |
571 $fp = fopen( $filename, 'w' ); |
570 $fp = fopen( $filename, 'w' ); |