From ba1d12bdfdff7f1c954e8459b4a64813fb2a0b29 Mon Sep 17 00:00:00 2001 From: Phie Date: Sun, 26 Jul 2020 19:39:29 +0200 Subject: rotate preview with exif data --- lib/Controller/NoteController.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Controller/NoteController.php b/lib/Controller/NoteController.php index 5ca9528..88b9b32 100755 --- a/lib/Controller/NoteController.php +++ b/lib/Controller/NoteController.php @@ -866,9 +866,27 @@ public function getOpusEncoder(){ $width = 400*$ratio; $height = 400; } - $src = imagecreatefromstring(file_get_contents($fn)); + $srcFile = file_get_contents($fn); + $src = imagecreatefromstring($srcFile); + + $dst = imagecreatetruecolor($width,$height); imagecopyresampled($dst,$src,0,0,0,0,$width,$height,$size[0],$size[1]); + $exif = exif_read_data($fn, 0, true); + if(!empty($exif)){ + $orientation = $exif['IFD0']['Orientation']; + switch($orientation) { + case 3: + $dst = imagerotate($dst, 180, 0); + break; + case 6: + $dst = imagerotate($dst, -90, 0); + break; + case 8: + $dst = imagerotate($dst, 90, 0); + break; + } + } imagedestroy($src); $fileOut = $data->newFile("preview_".$_FILES['media']['name'][0].".jpg"); array_push($files, "data/"."preview_".$_FILES['media']['name'][0].".jpg"); -- cgit v1.2.3