Skip to content

Commit

Permalink
Improve compression of record images.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuli Sillanpää committed Feb 23, 2015
1 parent 126effc commit 7e1e73b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions module/Finna/src/Finna/Cover/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ protected function processImageURL($url, $cache = true)
);
imagefill($imageGDResized, 0, 0, $background);

$quality = 90;

// If both dimensions are smaller than the new image,
// just copy to center. Otherwise resample to fit if necessary.
if ($width < $reqWidth && $height < $reqHeight) {
Expand All @@ -323,7 +325,7 @@ protected function processImageURL($url, $cache = true)
imagecopy(
$imageGDResized, $imageGD, $imgX, $imgY, 0, 0, $width, $height
);
if (!@imagejpeg($imageGDResized, $finalFile)) {
if (!@imagejpeg($imageGDResized, $finalFile, $quality)) {
return false;
}
} elseif ($width > $reqWidth || $height > $reqHeight) {
Expand All @@ -346,11 +348,11 @@ protected function processImageURL($url, $cache = true)
$newWidth, $newHeight, $width, $height
);
}
if (!@imagejpeg($imageGDResized, $finalFile)) {
if (!@imagejpeg($imageGDResized, $finalFile, $quality)) {
return false;
}
} else {
if (!@imagejpeg($imageGD, $finalFile)) {
if (!@imagejpeg($imageGD, $finalFile, $quality)) {
return false;
}
}
Expand Down

0 comments on commit 7e1e73b

Please sign in to comment.