-
Notifications
You must be signed in to change notification settings - Fork 0
/
deepfry.py
42 lines (31 loc) · 951 Bytes
/
deepfry.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
from PIL import Image, ImageEnhance, ImageFilter
from tqdm import tqdm
from pathlib import Path
import glob
INPUT_PATH="./archive/memes/memes"
OUTPUT_PATH="./out"
CONTRAST = 2
SHARPNESS = 4
BRIGHTNESS = 1.3
COLOR = 3
JPEG_QUALITY = 2
JPEG_ITERATIONS = 20
def deepfry(infile, outfile):
im = Image.open(infile)
if im.mode in ("RGBA", "P"):
im = im.convert("RGB")
enh = ImageEnhance.Contrast(im)
im = enh.enhance(CONTRAST)
enh = ImageEnhance.Sharpness(im)
im = enh.enhance(SHARPNESS)
enh = ImageEnhance.Brightness(im)
im = enh.enhance(BRIGHTNESS)
enh = ImageEnhance.Color(im)
im = enh.enhance(COLOR)
for i in range(1, JPEG_ITERATIONS):
im.save(outfile, "JPEG", optimize=True, quality=JPEG_QUALITY)
im = Image.open(outfile)
for path in tqdm(glob.glob("{INPUT_PATH}/*")):
path = Path(path)
deepfry(path, f"{OUTPUT_PATH}/{path.name}")