public static function fromFile(File $file)
{
$extension = strtolower($file->extension);
$function = null;
if ($extension === 'jpg') {
$extension = 'jpeg';
}
if (in_array($extension, array('gif', 'jpeg', 'png'))) {
$function = 'imagecreatefrom' . $extension;
}
if ($function === null || !is_callable($function)) {
throw new \InvalidArgumentException('Image type "' . $file->extension . '" cannot be processed by GD');
}
$image = $function(TL_ROOT . '/' . $file->path);
if ($image === false) {
throw new \RuntimeException('Image "' . $file->path . '" failed to be processed by GD');
}
return new static($image);
}