Spaces:
Runtime error
Runtime error
updated album cover
Browse files
app.py
CHANGED
@@ -127,95 +127,7 @@ def albumart(user_mood,key,name):
|
|
127 |
image.save(path)
|
128 |
return path
|
129 |
|
130 |
-
def overlay_images(background_image_path, foreground_image_path):
|
131 |
-
# Open the background and foreground images
|
132 |
-
background_image = Image.open(background_image_path).resize((512, 512))
|
133 |
-
foreground_image = Image.open(foreground_image_path).resize((1024, 768)).convert("RGBA")
|
134 |
-
|
135 |
-
# Create a new image with transparency
|
136 |
-
final_image = Image.new("RGBA", (1024, 768))
|
137 |
-
|
138 |
-
# Calculate the position to paste the background image at the center
|
139 |
-
paste_x = int((1024 - background_image.width) / 2)
|
140 |
-
paste_y = int((768 - background_image.height) / 2)
|
141 |
-
|
142 |
-
# Overlay the background image at the center of the final image
|
143 |
-
final_image.paste(background_image, (paste_x, paste_y))
|
144 |
-
|
145 |
-
# Overlay the foreground image on the background image
|
146 |
-
final_image.paste(foreground_image, (0, 0), mask=foreground_image)
|
147 |
-
|
148 |
-
# Convert the image mode to RGB (removing alpha channel)
|
149 |
-
final_image = final_image.convert("RGB")
|
150 |
-
|
151 |
-
# Return the final image
|
152 |
-
return final_image
|
153 |
-
|
154 |
-
|
155 |
-
background_image_path = "/content/input.jpg" # Path to the background image
|
156 |
-
foreground_image_path = "/content/Transparent CD Case Mockup2.png" # Path to the foreground PNG image
|
157 |
-
|
158 |
-
result_image = overlay_images(background_image_path, foreground_image_path)
|
159 |
-
|
160 |
-
result_image.save("result.jpg") # Save the final image to a file
|
161 |
-
result_image.show() # Display the final image
|
162 |
-
|
163 |
-
#!pip install imageio
|
164 |
|
165 |
-
from PIL import Image, ImageSequence
|
166 |
-
|
167 |
-
def overlay_images(background_image_path, foreground_image_path, num_frames=36, rotation_angle=10):
|
168 |
-
# Open the background and foreground images
|
169 |
-
background_image = Image.open(background_image_path).resize((512, 512))
|
170 |
-
foreground_image = Image.open(foreground_image_path).resize((1024, 768)).convert("RGBA")
|
171 |
-
|
172 |
-
# Create a new image with transparency
|
173 |
-
final_image = Image.new("RGBA", (1024, 768))
|
174 |
-
|
175 |
-
# Calculate the position to paste the background image at the center
|
176 |
-
paste_x = int((1024 - background_image.width) / 2)
|
177 |
-
paste_y = int((768 - background_image.height) / 2)
|
178 |
-
|
179 |
-
# Create a list to store the frames of the GIF animation
|
180 |
-
frames = []
|
181 |
-
|
182 |
-
# Calculate the center point of the background image
|
183 |
-
center_x = int(background_image.width / 2)
|
184 |
-
center_y = int(background_image.height / 2)
|
185 |
-
|
186 |
-
# Rotate the background image and create frames for the GIF animation
|
187 |
-
for angle in range(0, 360, rotation_angle):
|
188 |
-
# Create a copy of the background image
|
189 |
-
rotated_image = background_image.copy()
|
190 |
-
|
191 |
-
# Rotate the image by the specified angle around its center
|
192 |
-
rotated_image = rotated_image.rotate(angle, resample=Image.BICUBIC, center=(center_x, center_y))
|
193 |
-
|
194 |
-
# Overlay the rotated background image at the center of the final image
|
195 |
-
final_image.paste(rotated_image, (paste_x, paste_y))
|
196 |
-
|
197 |
-
# Overlay the foreground image on the background image
|
198 |
-
final_image.paste(foreground_image, (0, 0), mask=foreground_image)
|
199 |
-
|
200 |
-
# Append the current frame to the list of frames
|
201 |
-
frames.append(final_image.copy())
|
202 |
-
|
203 |
-
# Convert the image mode of frames to RGB (removing alpha channel)
|
204 |
-
frames_rgb = [frame.convert("RGB") for frame in frames]
|
205 |
-
|
206 |
-
# Save the frames as an animated GIF
|
207 |
-
output_path = "animation.gif"
|
208 |
-
frames_rgb[0].save(output_path, save_all=True, append_images=frames_rgb[1:], loop=0, duration=100,optimize=True, quality=100)
|
209 |
-
|
210 |
-
# Return the output path of the animated GIF
|
211 |
-
return output_path
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
#background_image_path = "/content/input.png" # Path to the background image
|
217 |
-
#foreground_image_path = "/content/Transparent CD Case Mockup2.png" # Path to the foreground PNG image
|
218 |
-
#rotation_angle = 10
|
219 |
|
220 |
#overlay_images(background_image_path, foreground_image_path)
|
221 |
|
|
|
127 |
image.save(path)
|
128 |
return path
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
|
132 |
#overlay_images(background_image_path, foreground_image_path)
|
133 |
|