Skip to content

Commit

Permalink
Merge pull request vufind-org#18 from samuli/image-compression
Browse files Browse the repository at this point in the history
Improve compression of record images.
  • Loading branch information
EreMaijala committed Feb 24, 2015
2 parents 030a588 + 7e1e73b commit df03a9f
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 df03a9f

Please sign in to comment.