From 28f56772470b876ca824f69e99c794cc5d50b290 Mon Sep 17 00:00:00 2001 From: Will Franklin Date: Thu, 24 Aug 2023 15:41:24 +0100 Subject: [PATCH 1/3] Rotate JPEG images if they have an Orientation tag --- .../image/image.controller.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/content-controllers/image/image.controller.php b/content-controllers/image/image.controller.php index d325d8d..3219c9b 100644 --- a/content-controllers/image/image.controller.php +++ b/content-controllers/image/image.controller.php @@ -24,8 +24,26 @@ class ImageController implements ContentController case 17: $ext = 'ico';break; // ico case 18: $ext = 'webp';break; // webp - case 2: //we clean up exif data of JPGs so GPS and other data is removed + case 2: + //we clean up exif data of JPGs so GPS and other data is removed $res = imagecreatefromjpeg($tmpfile); + + // rotate based on EXIF Orientation + $exif = exif_read_data($tmpfile); + if (!empty($exif['Orientation'])) { + switch ($exif['Orientation']) { + case 3: + $res = imagerotate($res, 180, 0); + break; + case 6: + $res = imagerotate($res, -90, 0); + break; + case 8: + $res = imagerotate($res, 90, 0); + break; + } + } + imagejpeg($res, $tmpfile, (defined('JPEG_COMPRESSION')?JPEG_COMPRESSION:90)); $ext = 'jpg'; break; From 2362af1e8ca56f1a2d2610e0f50dcdb5849dea02 Mon Sep 17 00:00:00 2001 From: Will Franklin Date: Thu, 24 Aug 2023 15:41:32 +0100 Subject: [PATCH 2/3] Fix docker build instructions --- rtfm/DOCKER.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtfm/DOCKER.md b/rtfm/DOCKER.md index 386d1eb..214ad8d 100644 --- a/rtfm/DOCKER.md +++ b/rtfm/DOCKER.md @@ -11,7 +11,7 @@ docker run -d -p 80:80 -e "TITLE=My own PictShare" -e "URL=http://localhost/" gh ### Building it ```bash -docker build -t pictshare . +docker build -t pictshare -f docker/Dockerfile . ``` ### Quick start From 7b4b27098d886effc98ff024b9c25b714df6b1d8 Mon Sep 17 00:00:00 2001 From: Will Franklin Date: Thu, 24 Aug 2023 16:30:11 +0100 Subject: [PATCH 3/3] Add support for flipping images too --- content-controllers/image/image.controller.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/content-controllers/image/image.controller.php b/content-controllers/image/image.controller.php index 3219c9b..584c1a2 100644 --- a/content-controllers/image/image.controller.php +++ b/content-controllers/image/image.controller.php @@ -32,12 +32,29 @@ class ImageController implements ContentController $exif = exif_read_data($tmpfile); if (!empty($exif['Orientation'])) { switch ($exif['Orientation']) { + case 2: + imageflip($res, IMG_FLIP_HORIZONTAL); + case 1: + // Nothing to do + break; + + case 4: + imageflip($res, IMG_FLIP_HORIZONTAL); + // Also rotate case 3: $res = imagerotate($res, 180, 0); break; + + case 5: + imageflip($res, IMG_FLIP_VERTICAL); + // Also rotate case 6: $res = imagerotate($res, -90, 0); break; + + case 7: + imageflip($res, IMG_FLIP_VERTICAL); + // Also rotate case 8: $res = imagerotate($res, 90, 0); break;