forked from antonmiakotin/snazzy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
63 lines (47 loc) · 2.07 KB
/
util.py
File metadata and controls
63 lines (47 loc) · 2.07 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from wand.image import Image
from wand.color import Color
from wand.drawing import Drawing
def crop_square_center(image):
width = image.width
height = image.height
image.crop(width=height, height=height, left=(width - height)/2, top=0)
def crop_center(image, width, height):
image_width = image.width
image_height = image.height
image.crop(width=width, height=height, left=(image_width - width)/2, top=(image_height-height)/2)
def crop_resize(image, size):
image.resize(int(size), int(size))
crop_center(image, width, height)
def overlay():
with Image(filename="booth_background.png") as overlay:
with Image(filename="0.jpg") as underlay:
underlay.composite_channel('default_channels', overlay, 'over', 0, 0)
underlay.save(filename="composited.jpg")
def blur_edges(image, border):
rect = Image(width=image.width, height=image.height, background=Color('white'))
drawing = Drawing()
drawing.rectangle(left=border, top=border, width=image.width - 2 * border, height=image.height - 2 * border, radius=100)
drawing(rect)
rect.negate()
rect.gaussian_blur(radius=10, sigma=15)
with Drawing() as draw:
draw.composite('multiply', 0, 0, image.width, image.height, rect)
draw(image)
def process(path, height_each):
image = Image(filename=path)
crop_square_center(image)
image.resize(width=1040, height=960)
return image
def composite_all(background, images, padding, width_each, height_each):
#First column
background.composite(images[0], padding, padding)
background.composite(images[1], padding, int(height_each + padding * 2))
background.composite(images[2], padding, int(height_each * 2 + padding * 3))
#Second column
col2_padding = int(padding * 3 + width_each)
background.composite(images[0], col2_padding, padding)
background.composite(images[1], col2_padding, int(height_each + padding * 2))
background.composite(images[2], col2_padding, int(height_each * 2 + padding * 3))
with Image(filename="booth_background.png") as overlay:
overlay.resize(width=overlay.width*2, height=overlay.height*2)
background.composite_channel('default_channels', overlay, 'over', 0, 0)