Programming Language PHP
Namespace Plank\Mediable\Exceptions
Class ImageManipulationException
Method/Function unknownOutputFormat
Total Examples 1
1 code examples of PHP Plank\Mediable\Exceptions\ImageManipulationException::unknownOutputFormat extracted from open source projects
/**
* @throws ImageManipulationException If output format cannot be determined
*/
private function determineOutputFormat(
ImageManipulation $manipulation,
Media $media
): string {
if ($format = $manipulation->getOutputFormat()) {
return $format;
}
// attempt to infer the format from the mime type
$mime = strtolower($media->mime_type);
$format = array_search($mime, ImageManipulation::MIME_TYPE_MAP);
if ($format !== false) {
return $format;
}
// attempt to infer the format from the file extension
$extension = strtolower($media->extension);
if (in_array($extension, ImageManipulation::VALID_IMAGE_FORMATS)) {
return $extension;
}
if ($extension === 'jpeg') {
return ImageManipulation::FORMAT_JPG;
}
if ($extension === 'tiff') {
return ImageManipulation::FORMAT_TIFF;
}
throw ImageManipulationException::unknownOutputFormat();
}