Skip to content

Instantly share code, notes, and snippets.

@salathe
Forked from J7mbo/gist:8317804
Last active January 2, 2016 14:39
Show Gist options
  • Save salathe/8317870 to your computer and use it in GitHub Desktop.
Save salathe/8317870 to your computer and use it in GitHub Desktop.
/**
* {@inheritdoc}
*
* @note Image dimensions returned as array(width, height)
*/
public function fetchMetaDataFrom($filePath)
{
if (!file_exists($filePath))
throw new MetaDataFileNotFoundException(sprintf("File %s could not be found for metadata retrieval", $filePath));
$metadata = @getimagesize($filePath);
if ($metadata === false)
throw new MetaDataFileNotReadableException(sprintf("File %s metadata couldn't be read. Permissions problem?", $filePath));
list($width, $height, $type, /** Skip $attr **/) = $metadata;
$extension = $this->resolveImageType($type);
if (!in_array($extension, $this->allowedImageTypes))
throw new MetaDataImageExtensionNotAllowedException(sprintf("File %s wasn't in allowed image types: %s", $extension, print_r($this->allowedImageTypes, true)));
return array($width, $height);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment