Created
October 31, 2014 14:08
-
-
Save jdeniau/94feba4a50986ee41c8e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
use stojg\crop\CropFace as BaseCropFace; | |
/** | |
* CropFace | |
*/ | |
class CropFace extends BaseCropFace | |
{ | |
/** | |
* Resize and crop the image so it dimensions matches $targetWidth and $targetHeight | |
* | |
* @param string $imagePath | |
* @param int $targetWidth | |
* @param int $targetHeight | |
* @return boolean|\Imagick | |
*/ | |
public function drawInformations($targetWidth, $targetHeight) | |
{ | |
//safe zone list | |
// First get the size that we can use to safely trim down the image without cropping any sides | |
$crop = $this->getSafeResizeOffset($this->originalImage, $targetWidth, $targetHeight); | |
// Resize the image | |
$this->originalImage->resizeImage($crop['width'], $crop['height'], \Imagick::FILTER_CUBIC, .5); | |
//ld($this->originalImage->getImageWidth(), $this->originalImage->getImageHeight()); | |
$safeZoneList = $this->getSafeZoneList(); | |
foreach ($safeZoneList as $safeZone) { | |
$draw = new \ImagickDraw(); | |
$draw->setFillColor('rgba(0, 200, 0, 0.4)'); | |
$draw->rectangle($safeZone['left'], $safeZone['top'], $safeZone['right'], $safeZone['bottom']); | |
$this->originalImage->drawImage($draw); | |
} | |
// Get the offset for cropping the image further | |
$offset = $this->getSpecialOffset($this->originalImage, $targetWidth, $targetHeight); | |
$imageWidth = $this->originalImage->getImageWidth(); | |
$imageHeight = $this->originalImage->getImageHeight(); | |
$rectangles = [ | |
[0, 0, $offset['x'], $imageHeight], | |
[0, 0, $imageWidth, $offset['y']], | |
[$offset['x'] + $targetWidth, 0, $imageWidth, $imageHeight], | |
[0, $offset['y'] + $targetHeight, $imageWidth, $imageHeight], | |
]; | |
foreach ($rectangles as $rectangle) { | |
$draw = new \ImagickDraw(); | |
$draw->setFillColor('rgba(0, 0, 0, 0.8)'); | |
$draw->rectangle($rectangle[0], $rectangle[1], $rectangle[2], $rectangle[3]); | |
$this->originalImage->drawImage($draw); | |
} | |
// Crop the image | |
//$this->originalImage->cropImage($targetWidth, $targetHeight, $offset['x'], $offset['y']); | |
return $this->originalImage; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment