Add abstract methods back to WP_Image_Editor and refresh phpdoc.

Props DH-Shredder, markoheijnen, kurtpayne, nacin
see #6821


git-svn-id: https://develop.svn.wordpress.org/trunk@22619 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2012-11-16 22:02:21 +00:00
parent 91d80348b8
commit d5c96a1e8b
3 changed files with 151 additions and 33 deletions

View File

@ -25,7 +25,7 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
} }
/** /**
* Checks to see if current environment supports GD * Checks to see if current environment supports GD.
* *
* @since 3.5.0 * @since 3.5.0
* @access public * @access public
@ -40,9 +40,9 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
} }
/** /**
* Loads image from $this->file into new GD Resource * Loads image from $this->file into new GD Resource.
* *
* @since 3.5 * @since 3.5.0
* @access protected * @access protected
* *
* @return boolean|\WP_Error * @return boolean|\WP_Error
@ -72,7 +72,7 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
} }
/** /**
* Sets or updates current image size * Sets or updates current image size.
* *
* @since 3.5.0 * @since 3.5.0
* @access protected * @access protected
@ -91,7 +91,7 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
} }
/** /**
* Checks to see if editor supports mime-type specified * Checks to see if editor supports the mime-type specified.
* *
* @since 3.5.0 * @since 3.5.0
* @access public * @access public
@ -107,7 +107,10 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
/** /**
* Resizes current image. * Resizes current image.
* Wrapper around _resize, since _resize returns a GD Resource * Wraps _resize, since _resize returns a GD Resource.
*
* @since 3.5.0
* @access public
* *
* @param int $max_w * @param int $max_w
* @param int $max_h * @param int $max_h
@ -153,6 +156,9 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
* Processes current image and saves to disk * Processes current image and saves to disk
* multiple sizes from single source. * multiple sizes from single source.
* *
* @since 3.5.0
* @access public
*
* @param array $sizes { {width, height}, ... } * @param array $sizes { {width, height}, ... }
* @return array * @return array
*/ */
@ -192,7 +198,7 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
* @param int $src_h The height to crop. * @param int $src_h The height to crop.
* @param int $dst_w Optional. The destination width. * @param int $dst_w Optional. The destination width.
* @param int $dst_h Optional. The destination height. * @param int $dst_h Optional. The destination height.
* @param int $src_abs Optional. If the source crop points are absolute. * @param boolean $src_abs Optional. If the source crop points are absolute.
* @return boolean|WP_Error * @return boolean|WP_Error
*/ */
public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) { public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) {
@ -250,7 +256,10 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
} }
/** /**
* Flips current image * Flips current image.
*
* @since 3.5.0
* @access public
* *
* @param boolean $horz Horizonal Flip * @param boolean $horz Horizonal Flip
* @param boolean $vert Vertical Flip * @param boolean $vert Vertical Flip
@ -277,7 +286,10 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
} }
/** /**
* Saves current in-memory image to file * Saves current in-memory image to file.
*
* @since 3.5.0
* @access public
* *
* @param string $destfilename * @param string $destfilename
* @param string $mime_type * @param string $mime_type
@ -335,7 +347,10 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
} }
/** /**
* Returns stream of current image * Returns stream of current image.
*
* @since 3.5.0
* @access public
* *
* @param string $mime_type * @param string $mime_type
*/ */

View File

@ -44,7 +44,7 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
} }
/** /**
* Loads image from $this->file into new Imagick Object * Loads image from $this->file into new Imagick Object.
* *
* @since 3.5.0 * @since 3.5.0
* @access protected * @access protected
@ -109,7 +109,7 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
} }
/** /**
* Sets or updates current image size * Sets or updates current image size.
* *
* @since 3.5.0 * @since 3.5.0
* @access protected * @access protected
@ -138,7 +138,7 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
} }
/** /**
* Checks to see if editor supports mime-type specified * Checks to see if editor supports the mime-type specified.
* *
* @since 3.5.0 * @since 3.5.0
* @access public * @access public
@ -163,6 +163,9 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
/** /**
* Resizes current image. * Resizes current image.
* *
* @since 3.5.0
* @access public
*
* @param int $max_w * @param int $max_w
* @param int $max_h * @param int $max_h
* @param boolean $crop * @param boolean $crop
@ -199,6 +202,9 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
* Processes current image and saves to disk * Processes current image and saves to disk
* multiple sizes from single source. * multiple sizes from single source.
* *
* @since 3.5.0
* @access public
*
* @param array $sizes * @param array $sizes
* @return array * @return array
*/ */
@ -246,11 +252,10 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
* @param int $src_h The height to crop. * @param int $src_h The height to crop.
* @param int $dst_w Optional. The destination width. * @param int $dst_w Optional. The destination width.
* @param int $dst_h Optional. The destination height. * @param int $dst_h Optional. The destination height.
* @param int $src_abs Optional. If the source crop points are absolute. * @param boolean $src_abs Optional. If the source crop points are absolute.
* @return boolean|WP_Error * @return boolean|WP_Error
*/ */
public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) { public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) {
// Not sure this is compatible.
if ( $src_abs ) { if ( $src_abs ) {
$src_w -= $src_x; $src_w -= $src_x;
$src_h -= $src_y; $src_h -= $src_y;
@ -302,14 +307,14 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
} }
/** /**
* Flips current image * Flips current image.
* *
* @since 3.5.0 * @since 3.5.0
* @access public * @access public
* *
* @param boolean $horz Horizontal Flip * @param boolean $horz Horizonal Flip
* @param boolean $vert Vertical Flip * @param boolean $vert Vertical Flip
* @returns boolean * @returns boolean|WP_Error
*/ */
public function flip( $horz, $vert ) { public function flip( $horz, $vert ) {
try { try {
@ -326,7 +331,10 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
} }
/** /**
* Saves current image to file * Saves current image to file.
*
* @since 3.5.0
* @access public
* *
* @param string $destfilename * @param string $destfilename
* @param string $mime_type * @param string $mime_type
@ -385,7 +393,10 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
} }
/** /**
* Streams current image to browser * Streams current image to browser.
*
* @since 3.5.0
* @access public
* *
* @param string $mime_type * @param string $mime_type
* @return boolean|WP_Error * @return boolean|WP_Error

View File

@ -62,8 +62,7 @@ abstract class WP_Image_Editor {
array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) ); array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) );
if ( ! $required_methods ) if ( ! $required_methods )
$required_methods = apply_filters( 'wp_image_editor_default_methods', $required_methods = array();
array( 'resize', 'multi_resize', 'crop', 'rotate', 'flip', 'stream' ) );
// Loop over each editor on each request looking for one which will serve this request's needs // Loop over each editor on each request looking for one which will serve this request's needs
foreach ( $request_order as $editor ) { foreach ( $request_order as $editor ) {
@ -80,19 +79,112 @@ abstract class WP_Image_Editor {
return false; return false;
} }
abstract protected function load(); // returns bool|WP_Error /**
* Loads image from $this->file into editor.
*
* @since 3.5.0
* @access protected
* @abstract
*
* @return boolean|WP_Error True if loaded; WP_Error on failure.
*/
abstract protected function load();
/**
* Saves current image to file.
*
* @since 3.5.0
* @access public
* @abstract
*
* @param string $destfilename
* @param string $mime_type
* @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string}
*/
abstract public function save( $destfilename = null, $mime_type = null ); abstract public function save( $destfilename = null, $mime_type = null );
/** /**
* Implement all of the below to support natively used functions: * Resizes current image.
* *
* public function resize( $max_w, $max_h, $crop = false ) * @since 3.5.0
* public function multi_resize( $sizes ) * @access public
* public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) * @abstract
* public function rotate( $angle ) *
* public function flip( $horz, $vert ) * @param int $max_w
* public function stream( $mime_type = null ) * @param int $max_h
* @param boolean $crop
* @return boolean|WP_Error
*/ */
abstract public function resize( $max_w, $max_h, $crop = false );
/**
* Processes current image and saves to disk
* multiple sizes from single source.
*
* @since 3.5.0
* @access public
* @abstract
*
* @param array $sizes
* @return array
*/
abstract public function multi_resize( $sizes );
/**
* Crops Image.
*
* @since 3.5.0
* @access public
* @abstract
*
* @param string|int $src The source file or Attachment ID.
* @param int $src_x The start x position to crop from.
* @param int $src_y The start y position to crop from.
* @param int $src_w The width to crop.
* @param int $src_h The height to crop.
* @param int $dst_w Optional. The destination width.
* @param int $dst_h Optional. The destination height.
* @param boolean $src_abs Optional. If the source crop points are absolute.
* @return boolean|WP_Error
*/
abstract public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false );
/**
* Rotates current image counter-clockwise by $angle.
*
* @since 3.5.0
* @access public
* @abstract
*
* @param float $angle
* @return boolean|WP_Error
*/
abstract public function rotate( $angle );
/**
* Flips current image.
*
* @since 3.5.0
* @access public
* @abstract
*
* @param boolean $horz Horizonal Flip
* @param boolean $vert Vertical Flip
* @return boolean|WP_Error
*/
abstract public function flip( $horz, $vert );
/**
* Streams current image to browser.
*
* @since 3.5.0
* @access public
* @abstract
*
* @param string $mime_type
* @return boolean|WP_Error
*/
abstract public function stream( $mime_type = null );
/** /**
* Checks to see if current environment supports the editor chosen. * Checks to see if current environment supports the editor chosen.
@ -110,7 +202,7 @@ abstract class WP_Image_Editor {
} }
/** /**
* Checks to see if editor supports mime-type specified * Checks to see if editor supports the mime-type specified.
* Must be overridden in a sub-class. * Must be overridden in a sub-class.
* *
* @since 3.5.0 * @since 3.5.0
@ -125,7 +217,7 @@ abstract class WP_Image_Editor {
} }
/** /**
* Gets dimensions of image * Gets dimensions of image.
* *
* @since 3.5.0 * @since 3.5.0
* @access public * @access public
@ -137,7 +229,7 @@ abstract class WP_Image_Editor {
} }
/** /**
* Sets current image size * Sets current image size.
* *
* @since 3.5.0 * @since 3.5.0
* @access protected * @access protected