X-Git-Url: http://positon.org/gitweb/?p=bizou.git;a=blobdiff_plain;f=functions.php;fp=functions.php;h=867bb4997d6a936906a15844a6fc36020ea9e47a;hp=ebad5041a7ac8b019fac0bdba4cb77d37902f4f3;hb=61e81e087eb8a83076870360678fe96a733447e6;hpb=aac71576e1d00d7f72519820146ddda52ab62291 diff --git a/functions.php b/functions.php index ebad504..867bb49 100644 --- a/functions.php +++ b/functions.php @@ -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);