public function resize($source, $destination = null, array $params = [])
{
if (!isset($destination)) {
$destination = $source;
}
try {
$image = $this->imagine->open($source);
$width = $image->getSize()->getWidth();
$height = $image->getSize()->getHeight();
$params = $this->normalizeResizeParameters($width, $height, $params);
$max_width = elgg_extract('w', $params);
$max_height = elgg_extract('h', $params);
$x1 = (int) elgg_extract('x1', $params, 0);
$y1 = (int) elgg_extract('y1', $params, 0);
$x2 = (int) elgg_extract('x2', $params, 0);
$y2 = (int) elgg_extract('y2', $params, 0);
if ($x2 > $x1 && $y2 > $y1) {
$crop_start = new Point($x1, $y1);
$crop_size = new Box($x2 - $x1, $y2 - $y1);
$image->crop($crop_start, $crop_size);
}
$target_size = new Box($max_width, $max_height);
$thumbnail = $image->resize($target_size);
$thumbnail->save($destination, ['jpeg_quality' => elgg_extract('jpeg_quality', $params, self::JPEG_QUALITY)]);
unset($image);
unset($thumbnail);
} catch (Exception $ex) {
_elgg_services()->logger->error($ex->getMessage());
return false;
}
return true;
}