Skip to content

Commit

Permalink
Added transparency
Browse files Browse the repository at this point in the history
  • Loading branch information
TomCasavant committed May 8, 2024
1 parent 45f30df commit 5b7e671
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions gb.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def get_recent_frames(self, directory, num_frames=100, gif_outline='gameboy.png'

self.build_gif(os.path.join(script_dir, "tmp"),
fps=5,
output_name="test.mp4",
output_name="previous.webm",
gif_outline=gif_outline
)
self.empty_directory(os.path.join(script_dir, "tmp"))
return os.path.join(script_dir, "test.mp4")
return os.path.join(script_dir, "previous.webm")

def empty_directory(self, directory):
"""Deletes all images in the provided directory"""
Expand All @@ -99,7 +99,7 @@ def empty_directory(self, directory):
for img in image_files:
os.remove(os.path.join(directory, img))

def build_gif(self, image_path, delete=True, fps=120, output_name="action.mp4", gif_outline="gameboy.png"):
def build_gif(self, image_path, delete=True, fps=120, output_name="action.webm", gif_outline="gameboy.png"):
"""Build a gif from a folder of images"""
# Get the directory of the current script
script_dir = os.path.dirname(os.path.realpath(__file__))
Expand All @@ -115,8 +115,8 @@ def build_gif(self, image_path, delete=True, fps=120, output_name="action.mp4",

gameboy_outline = Image.open(
os.path.join(script_dir, gif_outline)
).convert("RGB")
img = Image.open(os.path.join(gif_dir, file)).convert("RGB")
).convert("RGBA")
img = Image.open(os.path.join(gif_dir, file)).convert("RGBA")
img = img.resize((822, 733))
combined = gameboy_outline.copy()
combined.paste(img, (370, 319)) #370, 319 1192, 1052
Expand All @@ -128,7 +128,7 @@ def build_gif(self, image_path, delete=True, fps=120, output_name="action.mp4",
frames = images
save_path = os.path.join(script_dir, output_name)
clip = ImageSequenceClip(frames, fps=fps)
clip.write_videofile(save_path, codec="libx264")
clip.write_videofile(save_path, codec="libvpx")
if delete:
for img in images:
os.remove(img)
Expand Down

0 comments on commit 5b7e671

Please sign in to comment.