From bb06503bc6e5e27c4bda3bb4359ec82cfb3b5ed5 Mon Sep 17 00:00:00 2001 From: Matt Singleton Date: Sat, 3 Feb 2024 14:02:03 -0600 Subject: initial checkin --- convert_photo.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 convert_photo.py (limited to 'convert_photo.py') diff --git a/convert_photo.py b/convert_photo.py new file mode 100644 index 0000000..b1c9063 --- /dev/null +++ b/convert_photo.py @@ -0,0 +1,29 @@ +import argparse + +from PIL import Image, ImageOps + +from epdify import epdify, get_crop_box_and_orientation + +parser = argparse.ArgumentParser() +parser.add_argument("--dither-palette", default="perceived") +parser.add_argument("--final-palette", default="native") +parser.add_argument("-o", "--output-filename") +parser.add_argument("photo_filename") +args = parser.parse_args() + +img = Image.open(args.photo_filename) +img = ImageOps.exif_transpose(img) +is_portrait = img.width < img.height +box, orientation = get_crop_box_and_orientation(img.width, img.height, 0.6) +if orientation == "landscape": + size = (800, 480) +else: + size = (480, 800) +img = img.resize(size, resample=Image.Resampling.LANCZOS, box=box, reducing_gap=3) +img = epdify(img, args.dither_palette, args.final_palette) +if args.output_filename is None: + base, _ = args.photo_filename.rsplit('.', 1) + out_filename = f"{base}.epdified.bmp" +else: + out_filename = args.output_filename +img.save(out_filename, 'bmp') -- cgit v1.2.3