Skip to content

Commit

Permalink
Fixed GD thumbnailing of an image with an icc profile.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-KM committed Jun 23, 2019
1 parent 273f940 commit f0d14c2
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 4 deletions.
18 changes: 17 additions & 1 deletion application/src/File/Thumbnailer/Gd.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class Gd extends AbstractThumbnailer
*/
protected $origHeight;

/**
* @var string The profile icc of the original image.
*/
protected $icc;

/**
* Check whether the GD entension is loaded.
*
Expand Down Expand Up @@ -56,6 +61,8 @@ public function setSource(TempFile $source)
break;
case 'image/jpeg':
$origImage = imagecreatefromjpeg($sourcePath);
$inputPel = new \lsolesen\pel\PelJpeg($sourcePath);
$this->icc = $inputPel->getIcc();
break;
case 'image/png':
$origImage = imagecreatefrompng($sourcePath);
Expand All @@ -71,6 +78,7 @@ public function setSource(TempFile $source)
if (false === $origImage) {
throw new Exception\CannotCreateThumbnailException;
}

$this->origImage = $origImage;
$this->origWidth = imagesx($origImage);
$this->origHeight = imagesy($origImage);
Expand All @@ -97,7 +105,15 @@ public function create($strategy, $constraint, array $options = [])
}

imagedestroy($tempImage);
return $tempFile->getTempPath();

$tempPath = $tempFile->getTempPath();
if ($this->icc) {
$outputPel = new \lsolesen\pel\PelJpeg($tempPath);
$outputPel->setIcc($this->icc);
$outputPel->saveFile($tempPath);
}

return $tempPath;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"zendframework/zendxml": "^1.0.2",
"omeka/composer-addon-installer": "*",
"omeka-s-themes/default": "dev-develop",
"beberlei/doctrineextensions": "^1.0"
"beberlei/doctrineextensions": "^1.0",
"lsolesen/pel": "^0.9.6"
},
"require-dev": {
"phpunit/phpunit": "^5.7.23 || ^6.4.4",
Expand Down
59 changes: 57 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f0d14c2

Please sign in to comment.