Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from stefliekens/identify-pdfs
Browse files Browse the repository at this point in the history
Only open/read the first page when the file is a pdf
  • Loading branch information
veewee committed Jul 23, 2015
2 parents bfe00c2 + fe101ec commit 7493ec7
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Phpro/Filesystem/Metadata/Image/Identify.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ protected function parseIdentify(FileInterface $file, array $options = [])
{
try {
$image = $this->imagick;
$image->readImage($file->getPath());

$format = strtolower(pathinfo($file->getPath(), PATHINFO_EXTENSION));
$source = $this->alterSource($file->getPath(), $format);

$image->readImage($source);
$identifyData = $image->identifyImage();

if (isset($options['extended']) && $options['extended']) {
Expand Down Expand Up @@ -76,4 +80,22 @@ protected function hasSpotColors(Imagick $image)

return count($spotColors) ? true : false;
}

/**
* Makes it possible to change the source of a file based on the format.
* Only read/identify the first page of a PDF file.
*
* @param $source
* @param $format
*
* @return string
*/
protected function alterSource($source, $format)
{
if (strtolower($format) == 'pdf') {
return $source . '[0]';
}

return $source;
}
}

0 comments on commit 7493ec7

Please sign in to comment.