Rishi Desai commited on
Commit
bfa7d21
·
1 Parent(s): 99745bb

more gif stuff

Browse files
examples/comparison.gif ADDED

Git LFS Details

  • SHA256: 0ef9b29da7f1a30e3f9ffd1008e6d2f5d04c7b489aa6217f571e4a095a2a6b1b
  • Pointer size: 132 Bytes
  • Size of remote file: 6.62 MB
examples/create_comparison_gif.py CHANGED
@@ -4,7 +4,7 @@ from pathlib import Path
4
  from PIL import Image
5
  import numpy as np
6
 
7
- def create_comparison_gif(before_img_path, after_img_path, output_path=None, duration=100, frames=20):
8
  """
9
  Create a comparison GIF with a vertical bar revealing the 'after' image.
10
 
@@ -14,6 +14,8 @@ def create_comparison_gif(before_img_path, after_img_path, output_path=None, dur
14
  output_path (str, optional): Path for the output GIF. Defaults to 'comparison.gif'
15
  duration (int, optional): Duration of each frame in ms. Defaults to 100.
16
  frames (int, optional): Number of frames in the GIF. Defaults to 20.
 
 
17
 
18
  Returns:
19
  str: Path to the created GIF
@@ -21,7 +23,7 @@ def create_comparison_gif(before_img_path, after_img_path, output_path=None, dur
21
  # Default output path
22
  if output_path is None:
23
  output_path = 'comparison.gif'
24
-
25
  # Open images and ensure they have the same size
26
  before_img = Image.open(before_img_path)
27
  after_img = Image.open(after_img_path)
@@ -32,6 +34,16 @@ def create_comparison_gif(before_img_path, after_img_path, output_path=None, dur
32
 
33
  width, height = before_img.size
34
 
 
 
 
 
 
 
 
 
 
 
35
  # Create frames for the GIF
36
  gif_frames = []
37
 
@@ -77,6 +89,7 @@ def main():
77
  parser.add_argument('--output', '-o', help='Output path for the GIF', default='comparison.gif')
78
  parser.add_argument('--duration', '-d', type=int, help='Duration of each frame in ms', default=100)
79
  parser.add_argument('--frames', '-f', type=int, help='Number of frames to generate', default=20)
 
80
 
81
  args = parser.parse_args()
82
 
@@ -85,7 +98,8 @@ def main():
85
  args.after_image,
86
  args.output,
87
  args.duration,
88
- args.frames
 
89
  )
90
 
91
  print(f"Created comparison GIF: {output_path}")
 
4
  from PIL import Image
5
  import numpy as np
6
 
7
+ def create_comparison_gif(before_img_path, after_img_path, output_path=None, duration=100, frames=20, crop_pixels=0, bottom_bias=0.50):
8
  """
9
  Create a comparison GIF with a vertical bar revealing the 'after' image.
10
 
 
14
  output_path (str, optional): Path for the output GIF. Defaults to 'comparison.gif'
15
  duration (int, optional): Duration of each frame in ms. Defaults to 100.
16
  frames (int, optional): Number of frames in the GIF. Defaults to 20.
17
+ crop_pixels (int, optional): Number of pixels to crop from each side. Defaults to 0.
18
+ bottom_bias (float, optional): Percentage of additional cropping from the bottom. Defaults to 0.25 (25% more from the bottom).
19
 
20
  Returns:
21
  str: Path to the created GIF
 
23
  # Default output path
24
  if output_path is None:
25
  output_path = 'comparison.gif'
26
+
27
  # Open images and ensure they have the same size
28
  before_img = Image.open(before_img_path)
29
  after_img = Image.open(after_img_path)
 
34
 
35
  width, height = before_img.size
36
 
37
+ # Crop the images if crop_pixels is specified
38
+ if crop_pixels > 0:
39
+ left = crop_pixels
40
+ right = width - crop_pixels
41
+ top = int(crop_pixels * (1 - bottom_bias))
42
+ bottom = height - int(crop_pixels * (1 + bottom_bias))
43
+ before_img = before_img.crop((left, top, right, bottom))
44
+ after_img = after_img.crop((left, top, right, bottom))
45
+ width, height = before_img.size # Update width and height after cropping
46
+
47
  # Create frames for the GIF
48
  gif_frames = []
49
 
 
89
  parser.add_argument('--output', '-o', help='Output path for the GIF', default='comparison.gif')
90
  parser.add_argument('--duration', '-d', type=int, help='Duration of each frame in ms', default=100)
91
  parser.add_argument('--frames', '-f', type=int, help='Number of frames to generate', default=20)
92
+ parser.add_argument('--crop', '-c', type=int, help='Number of pixels to crop from each side', default=0)
93
 
94
  args = parser.parse_args()
95
 
 
98
  args.after_image,
99
  args.output,
100
  args.duration,
101
+ args.frames,
102
+ args.crop
103
  )
104
 
105
  print(f"Created comparison GIF: {output_path}")