1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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')
|