fixed bad thumb generation in case of wrong permission
added jpeg quality config
<?php
define('THUMB_SIZE', 100);
<?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.
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.
set_time_limit(20);
$ext = strtolower(substr($imgFile, -4));
set_time_limit(20);
$ext = strtolower(substr($imgFile, -4));
$img = imagecreatefromjpeg($imgFile);
$img = imagecreatefromjpeg($imgFile);
+ $exif = exif_read_data($imgFile);
+ } else {
$img = imagecreatefrompng($imgFile);
$img = imagecreatefrompng($imgFile);
+ }
+ if ($img === false) return ""; #read error (wrong permission...)
$w = imagesx($img);
$h = imagesy($img);
$w = imagesx($img);
$h = imagesy($img);
imagecopyresampled($newImg, $img, 0, 0, 0, 0, $newW, $newH, $w, $h);
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);
imagepng($newImg, $newImgFile);
imagedestroy($img);
imagedestroy($newImg);
imagedestroy($img);
imagedestroy($newImg);
<div id="images">
<?php foreach ($imageFiles as $file) { ?>
<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>
<?php if (isset($generating)) { ob_flush(); flush(); } ?>
<?php } ?>
</div>