-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Crop Effect: Added support for ImageMagick
Changes: - Abstract: Added support for "gravity", "repage", and "geometry" - Imagick: Added (untested) support for gravity - ImageMagick: Added support for crop
- Loading branch information
Showing
3 changed files
with
159 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/Charcoal/Image/Imagemagick/Effect/ImagemagickCropEffect.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Charcoal\Image\Imagemagick\Effect; | ||
|
||
use \Exception; | ||
|
||
use \Charcoal\Image\Effect\AbstractCropEffect; | ||
|
||
/** | ||
* Reisze Effect for the Imagemagick driver. | ||
* | ||
* See {@link http://www.imagemagick.org/script/command-line-processing.php#geometry Image Geometry} | ||
* for complete details about the geometry argument. | ||
*/ | ||
class ImagemagickCropEffect extends AbstractCropEffect | ||
{ | ||
/** | ||
* @param integer $width The crop width. | ||
* @param integer $height The crop height. | ||
* @param integer $x The x-position (in pixel) of the crop. | ||
* @param integer $y The y-position (in pixel) of the crop. | ||
* @return void | ||
*/ | ||
protected function doCrop($width, $height, $x, $y) | ||
{ | ||
$option = '-crop'; | ||
|
||
$geometry = $this->geometry(); | ||
if ($geometry) { | ||
$params = [ $option.' '.$geometry ]; | ||
} else { | ||
$params = [ '-gravity "'.$this->gravity().'"' ]; | ||
|
||
$size = $width.'x'.$height.($x >= 0 ? '+' : '').$x.($y >= 0 ? '+' : '').$y; | ||
$params[] = $option.' '.$size; | ||
} | ||
|
||
if ($this->repage()) { | ||
$params[] = '+repage'; | ||
} | ||
|
||
$this->image()->applyCmd(implode(' ', $params)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters