wp/wp-includes/class-wp-image-editor.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    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 	 * }
   173 	/**
   173 	/**
   174 	 * Gets dimensions of image.
   174 	 * Gets dimensions of image.
   175 	 *
   175 	 *
   176 	 * @since 3.5.0
   176 	 * @since 3.5.0
   177 	 *
   177 	 *
   178 	 * @return array {
   178 	 * @return int[] {
   179 	 *     Dimensions of the image.
   179 	 *     Dimensions of the image.
   180 	 *
   180 	 *
   181 	 *     @type int $width  The image width.
   181 	 *     @type int $width  The image width.
   182 	 *     @type int $height The image height.
   182 	 *     @type int $height The image height.
   183 	 * }
   183 	 * }
   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 ] )
   484 				$orientation = (int) $exif_data['Orientation'];
   483 				$orientation = (int) $exif_data['Orientation'];
   485 			}
   484 			}
   486 		}
   485 		}
   487 
   486 
   488 		/**
   487 		/**
   489 		 * Filters the `$orientation` value to correct it before rotating or to prevemnt rotating the image.
   488 		 * Filters the `$orientation` value to correct it before rotating or to prevent rotating the image.
   490 		 *
   489 		 *
   491 		 * @since 5.3.0
   490 		 * @since 5.3.0
   492 		 *
   491 		 *
   493 		 * @param int    $orientation EXIF Orientation value as retrieved from the image file.
   492 		 * @param int    $orientation EXIF Orientation value as retrieved from the image file.
   494 		 * @param string $file        Path to the image file.
   493 		 * @param string $file        Path to the image file.
   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' );