From 91b5e1b6d2b572bb0a5c31a9a2f28559d988e5eb Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Tue, 2 Aug 2022 18:47:24 +1000 Subject: [PATCH] created own version of exifautotran (placed into utils), and call it from ./ in non PROD and explciti /code in PROD - it deals with the Samsung created images with invalid SOS which dont autorotate --- shared.py | 5 ++++- utils/pa_exifautotran | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100755 utils/pa_exifautotran diff --git a/shared.py b/shared.py index e7335e3..36dcf59 100644 --- a/shared.py +++ b/shared.py @@ -33,13 +33,16 @@ if hostname == "lappy": PA_JOB_MANAGER_HOST="localhost" DB_URL = 'postgresql+psycopg2://pa:for_now_pa@localhost:5432/pa' # if we dont set the env or we are explicitly DEV, run web server on localhost & db on mara (port 65432) + PA_EXIF_ROTATER = './utils/pa_exifautotran' elif 'FLASK_ENV' not in os.environ or os.environ['FLASK_ENV'] == "development": PA_JOB_MANAGER_HOST="localhost" DB_URL = 'postgresql+psycopg2://pa:for_now_pa@mara.ddp.net:65432/pa' # if we explicitly are on PROD, run web server on localhost (pa_web container) & db on mara (port 5432 on padb container)- only accessed via internal docker ports) + PA_EXIF_ROTATER = './utils/pa_exifautotran' elif os.environ['FLASK_ENV'] == "production": PA_JOB_MANAGER_HOST="localhost" DB_URL = 'postgresql+psycopg2://pa:for_now_pa@padb/pa' + PA_EXIF_ROTATER = '/code/utils/pa_exifautotran' else: print( "ERROR: I do not know which environment (development, etc.) and which DB (on which host to use)" ) exit( -1 ) @@ -119,7 +122,7 @@ def GenThumb(fname,auto_rotate): try: if auto_rotate: # run cmdline util to re-orient jpeg (only changes if needed, and does it losslessly) - p = subprocess.run(["/usr/bin/exifautotran",fname] ) + p = subprocess.run([PA_EXIF_ROTATER,fname] ) im=Image.open(fname) # if we don't autorotate/touch the original, we still want the thumbnail oriented the right way else: diff --git a/utils/pa_exifautotran b/utils/pa_exifautotran new file mode 100755 index 0000000..30f2b5b --- /dev/null +++ b/utils/pa_exifautotran @@ -0,0 +1,40 @@ +#!/bin/sh +# pa_exifautotran [list of files] +# +# Transforms JPEG files so that Exif Orientation becomes 1 +# +# blatant copy of exitautotran shell script with: +# Minor change made to ignore failure of jpegtran (it was failing +# b/c Samsung images are incomplete, but the rotation works) +for i +do + case $i in + -v|--version) echo "$0 (pa variant)"; exit 0;; + -h|--help) + cat <&2 + jpegtran -copy all $transform "$i" > tempfile + rm "$i" + mv tempfile "$i" + jpegexiforient -1 "$i" + fi +done