honor jpeg orientation

fixed bad thumb generation in case of wrong permission
added jpeg quality config
This commit is contained in:
Marc MAURICE 2015-04-03 20:28:14 +02:00
parent aac71576e1
commit 61e81e087e
3 changed files with 18 additions and 6 deletions

View file

@ -1,5 +1,6 @@
<?php
define('THUMB_SIZE', 100);
define('JPEG_QUALITY', '80');
define('DATA_DIR', 'data');
define('IMAGES_DIR', 'images');
define('DATA_UMASK', 0002); # 0002: allow group to write for files created in data dir. change to 0022 to be more strict.

View file

@ -50,10 +50,13 @@ function getPreview($imgFile, $maxSize = THUMB_SIZE)
set_time_limit(20);
$ext = strtolower(substr($imgFile, -4));
if ($ext == ".jpg")
if ($ext == ".jpg") {
$img = imagecreatefromjpeg($imgFile);
else
$exif = exif_read_data($imgFile);
} else {
$img = imagecreatefrompng($imgFile);
}
if ($img === false) return ""; #read error (wrong permission...)
$w = imagesx($img);
$h = imagesy($img);
@ -82,10 +85,17 @@ function getPreview($imgFile, $maxSize = THUMB_SIZE)
imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
if ($ext == ".jpg")
imagejpeg($newImg, $newImgFile);
else
if ($ext == ".jpg") {
if (!empty($exif['Orientation'])) {
$orientation = $exif['Orientation'];
if ($orientation === 3) $newImg = imagerotate($newImg, 180, 0);
elseif ($orientation === 6) $newImg = imagerotate($newImg, -90, 0);
elseif ($orientation === 8) $newImg = imagerotate($newImg, 90, 0);
}
imagejpeg($newImg, $newImgFile, JPEG_QUALITY);
} else {
imagepng($newImg, $newImgFile);
}
imagedestroy($img);
imagedestroy($newImg);

View file

@ -74,7 +74,8 @@ a {
<div id="images">
<?php foreach ($imageFiles as $file) { ?>
<div class="square"><div class="image imagepreview"><a href="<?= $file["link"] ?>"><img src="<?= $rootUrl.getPreview($file["file"]) ?>" alt="<?= $file["name"] ?>" /></a></div><?php plugins_include("after_thumb.php") ?></div>
<?php $previewfile = $rootUrl.getPreview($file["file"]) ?>
<div class="square"><div class="image imagepreview"><a href="<?= $file["link"] ?>"><img src="<?= $previewfile ?>" alt="<?= $file["name"] ?>" /></a></div><?php plugins_include("after_thumb.php") ?></div>
<?php if (isset($generating)) { ob_flush(); flush(); } ?>
<?php } ?>
</div>