Remove duplicate code in PhotoDriver classes.
cropImage is just a special case of cropImageRect, no need to duplicate all the code.
This commit is contained in:
parent
e6dadb215e
commit
b9df4c99cf
@ -80,8 +80,18 @@ abstract class PhotoDriver {
|
||||
|
||||
abstract public function flip($horiz = true, $vert = false);
|
||||
|
||||
abstract public function cropImage($max, $x, $y, $w, $h);
|
||||
|
||||
/**
|
||||
* @brief Crops the image.
|
||||
*
|
||||
* @param int $maxx width of the new image
|
||||
* @param int $maxy height of the new image
|
||||
* @param int $x x-offset for region
|
||||
* @param int $y y-offset for region
|
||||
* @param int $w width of region
|
||||
* @param int $h height of region
|
||||
*
|
||||
* @return boolean|void false on failure
|
||||
*/
|
||||
abstract public function cropImageRect($maxx, $maxy, $x, $y, $w, $h);
|
||||
|
||||
/**
|
||||
@ -299,6 +309,26 @@ abstract class PhotoDriver {
|
||||
$this->doScaleImage($dim, $dim);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Crops a square image.
|
||||
*
|
||||
* @see cropImageRect()
|
||||
*
|
||||
* @param int $max size of the new image
|
||||
* @param int $x x-offset for region
|
||||
* @param int $y y-offset for region
|
||||
* @param int $w width of region
|
||||
* @param int $h height of region
|
||||
*
|
||||
* @return boolean|void false on failure
|
||||
*/
|
||||
public function cropImage($max, $x, $y, $w, $h) {
|
||||
if(! $this->is_valid())
|
||||
return false;
|
||||
|
||||
$this->cropImageRect($max, $max, $x, $y, $w, $h);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads exif data from a given filename.
|
||||
*
|
||||
|
@ -119,24 +119,6 @@ class PhotoGd extends PhotoDriver {
|
||||
$this->setDimensions(); // Shouldn't really be necessary
|
||||
}
|
||||
|
||||
public function cropImage($max, $x, $y, $w, $h) {
|
||||
if(!$this->is_valid())
|
||||
return false;
|
||||
|
||||
$dest = imagecreatetruecolor($max, $max);
|
||||
imagealphablending($dest, false);
|
||||
imagesavealpha($dest, true);
|
||||
if($this->type == 'image/png')
|
||||
imagefill($dest, 0, 0, imagecolorallocatealpha($dest, 0, 0, 0, 127)); // fill with alpha
|
||||
|
||||
imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h);
|
||||
if($this->image)
|
||||
imagedestroy($this->image);
|
||||
|
||||
$this->image = $dest;
|
||||
$this->setDimensions();
|
||||
}
|
||||
|
||||
public function cropImageRect($maxx, $maxy, $x, $y, $w, $h) {
|
||||
if(! $this->is_valid())
|
||||
return false;
|
||||
|
@ -169,24 +169,6 @@ class PhotoImagick extends PhotoDriver {
|
||||
$this->setDimensions(); // Shouldn't really be necessary
|
||||
}
|
||||
|
||||
public function cropImage($max,$x,$y,$w,$h) {
|
||||
if(!$this->is_valid())
|
||||
return false;
|
||||
|
||||
$this->image->setFirstIterator();
|
||||
do {
|
||||
$this->image->cropImage($w, $h, $x, $y);
|
||||
/*
|
||||
* We need to remove the canvas,
|
||||
* or the image is not resized to the crop:
|
||||
* http://php.net/manual/en/imagick.cropimage.php#97232
|
||||
*/
|
||||
$this->image->setImagePage(0, 0, 0, 0);
|
||||
} while($this->image->nextImage());
|
||||
|
||||
$this->doScaleImage($max, $max);
|
||||
}
|
||||
|
||||
public function cropImageRect($maxx, $maxy, $x, $y, $w, $h) {
|
||||
if(! $this->is_valid())
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user