-
Notifications
You must be signed in to change notification settings - Fork 1
/
liquid_input.sh
49 lines (40 loc) · 1.7 KB
/
liquid_input.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# generates a liquid gif using an input image.
# usage: ./liquid_input.sh Replace inputimage with your input image. After a
# while a liquid gif be created with your input image as its source. If you
# use a gif as input the duration of the output gif will be taken from its
# shortest input. The animated displacement map generated by ImageMagick
# is 36 frames. If the input gif has 12 frames the output gif will be 12
# frames but will be cut off and won't loop seamlessly. Similarly, if the
# input gif is 37 frames it will still output a gif of 36 frames and won't
# loop seamlessly.
# get width and height of the input image
width=`convert $1 -coalesce -flatten -format "%[fx:w]" info:`
height=`convert $1 -coalesce -flatten -format "%[fx:h]" info:`
inputfile=$(basename -- "$1")
extension="${inputfile##*.}"
# generate random number for blur
blur=$(echo $((5 + (RANDOM % 20))))
# generate random number for the frquency of the sinusoid function
frequency=$(echo $((1 + (RANDOM % 5))))
# I mostly stole this bit from here https://www.imagemagick.org/Usage/canvas/#random_ripples
for i in `seq 0 10 359`; do
j=`expr $i \* 5`
convert \( -size "$width"x"$height" xc: +noise Random \) \
-channel G \
-function Sinusoid 1,${i} \
-virtual-pixel tile -blur 0x10 -auto-level \
-function Sinusoid 2.5,${j} \
-separate +channel miff:-
done | convert miff:- -set delay 12 -loop 0 displacement_map.gif
# and here all parts are composited into the output gif
convert \
-dispose background \
\( $1 -coalesce \) null: \
displacement_map.gif \
-compose displace \
-define compose:args=30x40 \
-layers composite \
${inputfile%.*}_liquid."$extension"
# clean up temporary files
rm displacement_map.gif