PhotoShow
PhotoShow copied to clipboard
Allow non quadratic thumbnails: width, height, optional borders (code attached)
I would like to to generate non quadratic thumbnails, too. This could be done by specifying:
thumbnail width:
The default values just represent the guessed current behavior, but I would e.g. like to change to this: width: 260 height: 195 crop: off add borders: on
People like the author might prefer cropped pictures (as it is), but I prefer to see the full picture in the thumbnail already, even if there is need to add borders then to achieve same dimension for all images.
I also show some code how I did it so far, but it's in Python 3.6 and might serve just as template: (on the other hand the thumbnail method used here is quick like hell, in tests it was fastest so far)
import os
from PIL import Image, ImageOps
THUMBS_PATH = 'f:/out/'
MAX_SIZE = (260,195) # 7x7
ADD_BORDERS = True
def create_thumbnail(in_path):
im = Image.open(in_path)
im.thumbnail(MAX_SIZE, Image.ANTIALIAS)
out_path = THUMBS_PATH + os.path.basename(in_path)
# Extend image with border if width or height smaller than MAX_SIZE
if ADD_BORDERS:
dw = MAX_SIZE[0] - im.size[0]
dh = MAX_SIZE[1] - im.size[1]
dw_half = int(dw / 2)
dh_half = int(dh / 2)
ltrb_border = (dw_half, dh_half, dw - dw_half, dh - dh_half)
im_border = ImageOps.expand(im, border=ltrb_border, fill='black')
im_border.save(out_path, 'JPEG')
else:
im.save(out_path, 'JPEG')
Additionally, but less important, I would like that you can also disable generating "web images" (the "thumbs" with _small suffix), instead just show the original picture (reason: hdd health).