-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsketchify.py
executable file
·32 lines (28 loc) · 1.34 KB
/
sketchify.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
#!/usr/bin/env python
import sys, os
from PIL import Image, ImageOps, ImageChops, ImageFont, ImageDraw, ImageFilter
# Make an image more closely resemble a pen drawing, with optional shading and coloring
def sketchify(sourceImage, colorized=True, sketchOnly=False):
sketch=ImageOps.invert(ImageOps.autocontrast(sourceImage).filter(ImageFilter.FIND_EDGES))
if sketchOnly:
return sketch
if(colorized):
sourceImage=ImageOps.posterize(sourceImage, 2)
else:
sourceImage=ImageOps.grayscale(sourceImage)
sourceImage=sourceImage.convert("RGBA")
sketch=sketch.convert("RGBA")
merged=Image.blend(sourceImage, sketch, 0.5)
return merged
# Run sketchify and then fit to a particular size, followed by the addition of a gutter
def panelify(sourceImage, targetSize, borderWidth=5, colorized=True, sketchOnly=False):
sourceImage=sketchify(sourceImage, colorized, sketchOnly)
sourceImage=ImageOps.fit(sourceImage, targetSize)
frame=Image.new("RGBA", targetSize, "#ffff")
frame.paste(sourceImage.resize((targetSize[0]-(2*borderWidth), targetSize[1]-(2*borderWidth))), (borderWidth, borderWidth))
return frame
if __name__=="__main__":
sourceImage=Image.open(sys.argv[1]).convert("RGB")
#merged=sketchify(sourceImage, True)
merged=panelify(sourceImage, sourceImage.size)
merged.save("merged.png")