Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed GD thumbnailing of an image with an icc profile. #1421

Merged
merged 1 commit into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.