public static function create($image, $size = null)
{
@trigger_error('Using Image::create() has been deprecated and will no longer work in Contao 5.0. Use the contao.image.image_factory service instead.', E_USER_DEPRECATED);
if (is_string($image)) {
$image = new \File(rawurldecode($image));
}
/** @var Image $imageObj */
$imageObj = new static($image);
// tl_image_size ID as resize mode
if (is_array($size) && !empty($size[2]) && is_numeric($size[2])) {
$size = (int) $size[2];
}
if (is_array($size)) {
$size = $size + array(0, 0, 'crop');
$imageObj->setTargetWidth($size[0])->setTargetHeight($size[1])->setResizeMode($size[2]);
} elseif (($imageSize = \ImageSizeModel::findByPk($size)) !== null) {
$imageObj->setTargetWidth($imageSize->width)->setTargetHeight($imageSize->height)->setResizeMode($imageSize->resizeMode)->setZoomLevel($imageSize->zoom);
}
$fileRecord = \FilesModel::findByPath($image->path);
// Set the important part
if ($fileRecord !== null && $fileRecord->importantPartWidth && $fileRecord->importantPartHeight) {
$imageObj->setImportantPart(array('x' => (int) $fileRecord->importantPartX, 'y' => (int) $fileRecord->importantPartY, 'width' => (int) $fileRecord->importantPartWidth, 'height' => (int) $fileRecord->importantPartHeight));
}
return $imageObj;
}