Jeffgold commited on
Commit
cc2708d
·
verified ·
1 Parent(s): ccfb6c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -5
app.py CHANGED
@@ -25,19 +25,39 @@ def create_gif(editor1_output, editor2_output, transition_type):
25
  frame = Image.new('RGBA', size)
26
  frame.paste(img1, (0, 0))
27
  frame.paste(img2.crop((0, 0, i, size[1])), (full_width - i, 0), mask=img2.crop((0, 0, i, size[1])))
 
 
28
  frames.append(frame.convert('P', palette=Image.ADAPTIVE))
29
 
30
  for i in range(full_width, 0, -step):
31
  frame = Image.new('RGBA', size)
32
  frame.paste(img2, (0, 0))
33
  frame.paste(img1.crop((0, 0, i, size[1])), (full_width - i, 0), mask=img1.crop((0, 0, i, size[1])))
 
 
34
  frames.append(frame.convert('P', palette=Image.ADAPTIVE))
35
  else: # rotate transition
 
 
 
 
 
 
 
36
  for angle in range(0, 360, 360 // total_frames):
37
- mask = Image.new('L', size, 0)
38
- draw = ImageDraw.Draw(mask)
39
- draw.pieslice([0, 0, size[0], size[1]], -90, angle - 90, fill=255)
40
- frame = Image.composite(img2, img1, mask)
 
 
 
 
 
 
 
 
 
41
  frames.append(frame.convert('P', palette=Image.ADAPTIVE))
42
 
43
  # Save as GIF
@@ -94,4 +114,4 @@ with gr.Blocks() as iface:
94
  )
95
 
96
  # Launch the interface
97
- iface.launch(share=True)
 
25
  frame = Image.new('RGBA', size)
26
  frame.paste(img1, (0, 0))
27
  frame.paste(img2.crop((0, 0, i, size[1])), (full_width - i, 0), mask=img2.crop((0, 0, i, size[1])))
28
+ draw = ImageDraw.Draw(frame)
29
+ draw.line((full_width - i, 0, full_width - i, size[1]), fill=(0, 255, 0), width=2)
30
  frames.append(frame.convert('P', palette=Image.ADAPTIVE))
31
 
32
  for i in range(full_width, 0, -step):
33
  frame = Image.new('RGBA', size)
34
  frame.paste(img2, (0, 0))
35
  frame.paste(img1.crop((0, 0, i, size[1])), (full_width - i, 0), mask=img1.crop((0, 0, i, size[1])))
36
+ draw = ImageDraw.Draw(frame)
37
+ draw.line((full_width - i, 0, full_width - i, size[1]), fill=(0, 255, 0), width=2)
38
  frames.append(frame.convert('P', palette=Image.ADAPTIVE))
39
  else: # rotate transition
40
+ mask_size = (size[0] * 2, size[1] * 2)
41
+ mask = Image.new('L', mask_size, 0)
42
+ draw = ImageDraw.Draw(mask)
43
+ draw.rectangle([size[0], 0, mask_size[0], mask_size[1]], fill=255)
44
+
45
+ center_x, center_y = size[0] // 2, size[1] // 2
46
+
47
  for angle in range(0, 360, 360 // total_frames):
48
+ rotated_mask = mask.rotate(angle, center=(mask_size[0] // 2, mask_size[1] // 2), expand=False)
49
+ cropped_mask = rotated_mask.crop((size[0] // 2, size[1] // 2, size[0] // 2 + size[0], size[1] // 2 + size[1]))
50
+ frame = Image.composite(img1, img2, cropped_mask)
51
+
52
+ draw = ImageDraw.Draw(frame)
53
+ reverse_angle = -angle + 90
54
+ end_x1 = center_x + int(size[0] * 1.5 * cos(radians(reverse_angle)))
55
+ end_y1 = center_y + int(size[1] * 1.5 * sin(radians(reverse_angle)))
56
+ end_x2 = center_x - int(size[0] * 1.5 * cos(radians(reverse_angle)))
57
+ end_y2 = center_y - int(size[1] * 1.5 * sin(radians(reverse_angle)))
58
+ draw.line([center_x, center_y, end_x1, end_y1], fill=(0, 255, 0), width=3)
59
+ draw.line([center_x, center_y, end_x2, end_y2], fill=(0, 255, 0), width=3)
60
+
61
  frames.append(frame.convert('P', palette=Image.ADAPTIVE))
62
 
63
  # Save as GIF
 
114
  )
115
 
116
  # Launch the interface
117
+ iface.launch(share=True)