public function crop(&$image, $cropWidth, $cropHeight, $position = 'center', $offsetX = 0, $offsetY = 0)
{
if ($image->isAnimated()) {
// Ignore animated GIF for now
return $this;
}
if ('smart' === $position) {
// Smart crop
list($x, $y) = $this->_smartCrop($image, $cropWidth, $cropHeight);
} else {
// Turn into an instance of Position
$position = new Position($position, $offsetX, $offsetY);
// Crop position as x,y coordinates
list($x, $y) = $position->getXY($image->getWidth(), $image->getHeight(), $cropWidth, $cropHeight);
}
$x += $offsetX;
$y += $offsetY;
// Create blank image
$newImageResource = imagecreatetruecolor($cropWidth, $cropHeight);
// Now crop
imagecopyresampled($newImageResource, $image->getCore(), 0, 0, $x, $y, $cropWidth, $cropHeight, $cropWidth, $cropHeight);
// Free memory of old resource
imagedestroy($image->getCore());
// Cropped image instance
$image = new Image($newImageResource, $image->getImageFile(), $cropWidth, $cropHeight, $image->getType());
return $this;
}