Skip to content

Commit

Permalink
Add imagemagick use-cropbox for PDFs
Browse files Browse the repository at this point in the history
Handles PDFs that define a larger page and smaller cropping area for
display. Can be opted out of with a thumbnailer option
  • Loading branch information
zerocrates committed Jun 28, 2024
1 parent 620a1af commit d99a1d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions application/src/File/Thumbnailer/ImageMagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public function create($strategy, $constraint, array $options = [])
$commandArgs = [$this->convertPath];
if ($mediaType == 'application/pdf') {
$commandArgs[] = '-density 150';
if ($this->getOption('pdfUseCropBox', true)) {
$commandArgs[] = '-define pdf:use-cropbox=true';
}
}
$commandArgs[] = escapeshellarg($origPath);
$commandArgs = array_merge($commandArgs, $args);
Expand Down
3 changes: 3 additions & 0 deletions application/src/File/Thumbnailer/Imagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public function create($strategy, $constraint, array $options = [])
$imagick = new ImagickPhp;
if ($mediaType == 'application/pdf') {
$imagick->setResolution(150, 150);
if ($this->getOption('pdfUseCropBox', true)) {
$imagick->setOption('pdf:use-cropbox', true);
}
}
$imagick->readImage($origPath);
} catch (ImagickException $e) {
Expand Down

0 comments on commit d99a1d7

Please sign in to comment.