Created
May 17, 2019 10:50
-
-
Save hibikidesu/bd134e51e93d8ac745a9b3e72635ea43 to your computer and use it in GitHub Desktop.
Pixiv Ugora to GIF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def download_ugoira(ugoira_zip: BytesIO, data: dict, filename: str): | |
if not data.get("ugoira_metadata"): | |
raise Exception("Not valid ugoira data") | |
delay = 0 | |
frames = [] | |
raw_frames = data["ugoira_metadata"]["frames"] | |
with zipfile.ZipFile(ugoira_zip) as file: | |
for frame in raw_frames: | |
frames.append(imageio.imread(file.read(frame["file"]))) | |
delay = frame["delay"] | |
with imageio.get_writer(filename, mode="I", duration=delay / 1000) as gif: | |
for frame in frames: | |
gif.append_data(frame) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment