yangtb24 commited on
Commit
89dc51a
·
verified ·
1 Parent(s): d5302bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -28,7 +28,7 @@ HTML_CONTENT = """
28
  <h1>GIF Generator</h1>
29
  <form id="upload-form" enctype="multipart/form-data">
30
  <input type="file" name="images" accept="image/*" multiple>
31
- <input type="number" name="fps" placeholder="Frames per second" value="10" min="1" max="60">
32
  <button type="button" id="generate-button">Generate GIF</button>
33
  </form>
34
  <div id="gif-container" style="display:none;">
@@ -76,7 +76,7 @@ def index():
76
  def upload():
77
  try:
78
  files = request.files.getlist('images')
79
- fps = int(request.form.get('fps', 10))
80
  if not files:
81
  return "No images uploaded", 400
82
 
@@ -103,9 +103,9 @@ def upload():
103
  resized_img = img.resize((max_width, max_height), Image.LANCZOS)
104
  resized_images.append(resized_img)
105
 
106
- # Generate GIF using imageio
107
  gif_bytes = BytesIO()
108
- mimwrite(gif_bytes, [img for img in resized_images], format='GIF', fps=fps)
109
  gif_bytes.seek(0)
110
  gif_base64 = base64.b64encode(gif_bytes.read()).decode('utf-8')
111
  gif_url = f'data:image/gif;base64,{gif_base64}'
 
28
  <h1>GIF Generator</h1>
29
  <form id="upload-form" enctype="multipart/form-data">
30
  <input type="file" name="images" accept="image/*" multiple>
31
+ <input type="number" name="delay" placeholder="Delay (ms)" value="100" min="1" >
32
  <button type="button" id="generate-button">Generate GIF</button>
33
  </form>
34
  <div id="gif-container" style="display:none;">
 
76
  def upload():
77
  try:
78
  files = request.files.getlist('images')
79
+ delay_ms = int(request.form.get('delay', 100))
80
  if not files:
81
  return "No images uploaded", 400
82
 
 
103
  resized_img = img.resize((max_width, max_height), Image.LANCZOS)
104
  resized_images.append(resized_img)
105
 
106
+ # Generate GIF using imageio with loop and duration
107
  gif_bytes = BytesIO()
108
+ mimwrite(gif_bytes, [img for img in resized_images], format='GIF', loop=0, duration=delay_ms/1000)
109
  gif_bytes.seek(0)
110
  gif_base64 = base64.b64encode(gif_bytes.read()).decode('utf-8')
111
  gif_url = f'data:image/gif;base64,{gif_base64}'