Skip to content

Instantly share code, notes, and snippets.

@hibikidesu
Created May 17, 2019 10:50
Show Gist options
  • Save hibikidesu/bd134e51e93d8ac745a9b3e72635ea43 to your computer and use it in GitHub Desktop.
Save hibikidesu/bd134e51e93d8ac745a9b3e72635ea43 to your computer and use it in GitHub Desktop.
Pixiv Ugora to GIF
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