added ability to auto-rotate jpegs as we import them. The auto-rotation uses /usr/bin/exifautotran which rotates losslessly, and we optimised to then not also re-rotate the thumbmail. This address a few bugs in the 90s, including the one where Mandys photos were not getting faces (they were rotated), and without really doing anything the odd one where we sometimes lost tmp_locn on first load after db recreation - I cant reproduce so ignoring it
This commit is contained in:
19
shared.py
19
shared.py
@@ -3,6 +3,7 @@ import os
|
||||
import face_recognition
|
||||
import io
|
||||
import base64
|
||||
import subprocess
|
||||
from PIL import Image, ImageOps
|
||||
|
||||
class PA:
|
||||
@@ -114,13 +115,21 @@ def SymlinkName(ptype, path, file):
|
||||
|
||||
# generates the thumbnail for an image - uses THUMBSIZE, and deals with non RGB images, and rotated images (based on exif)
|
||||
# returns data for thumbnail and original width and height, which gets stored in DB. Used when re-scaling viewed thumbs (refimgs on person page)
|
||||
def GenThumb(fname):
|
||||
def GenThumb(fname,auto_rotate):
|
||||
try:
|
||||
im_orig = Image.open(fname)
|
||||
if im_orig.format == 'JPEG':
|
||||
im = ImageOps.exif_transpose(im_orig)
|
||||
if auto_rotate:
|
||||
# run cmdline util to re-orient jpeg (only changes if needed, and does it losslessly)
|
||||
print( f"exifautotran {fname}")
|
||||
p = subprocess.run(["/usr/bin/exifautotran",fname] )
|
||||
im=Image.open(fname)
|
||||
# if we don't autorotate/touch the original, we still want the thumbnail oriented the right way
|
||||
else:
|
||||
im = im_orig
|
||||
im_orig = Image.open(fname)
|
||||
if im_orig.format == 'JPEG':
|
||||
im = ImageOps.exif_transpose(im_orig)
|
||||
else:
|
||||
im = im_orig
|
||||
# if mode isn't RGB thumbnail fails, so force it if needed
|
||||
if im.mode != "RGB":
|
||||
im = im.convert('RGB')
|
||||
orig_w, orig_h = im.size
|
||||
|
||||
Reference in New Issue
Block a user