Created
January 28, 2019 20:07
-
-
Save jb3/9d235aa600c47289625d27f0a71b7b98 to your computer and use it in GitHub Desktop.
Apply a liquid rescale to a set of images to construct a gif of distortion.
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
#!/usr/bin/env python3 | |
# USAGE NOTES | |
# | |
# - You must create a directory called pngs | |
# - Once you have created your images you must run the following command to create a gif: | |
# convert -delay 1x8 `seq -f pngs/out-%03g.png 0 1 40` -coalesce out.gif | |
# | |
# This script depends on imagemagick, liblqr (liquid rescale) and wand for python (pip install Wand) | |
from wand.image import Image | |
from wand.display import display | |
import operator | |
original = Image(filename="meme.png") | |
iteration = 0 | |
distorted = [original] | |
for i in range(0, 40): | |
print("Processing frame {}/40".format(i)) | |
last_frame = distorted[::-1][0].clone() | |
last_frame.liquid_rescale(width=int(last_frame.width * 0.9), height=int(last_frame.height * 0.9), | |
delta_x=1, rigidity=0) | |
last_frame.resize(original.width, original.height) | |
distorted.append(last_frame) | |
for i, frame in enumerate(distorted): | |
print("Saving image {:03}".format(i)) | |
frame.save(filename="pngs/out-{:03}.png".format(i)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment