Last active
May 27, 2023 07:09
-
-
Save kana/ac6975cee901acc2b0626dd075204501 to your computer and use it in GitHub Desktop.
Generate "sunrise" gif for Slack emoji.
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
#!/bin/bash | |
set -euo pipefail | |
trap "rm -f ,$$,*" EXIT | |
border=4 | |
colors=256 | |
delay=6 | |
frames=30 | |
rays=10 | |
while (( $# > 0 )) | |
do | |
case "$1" in | |
-b) | |
border="$2" | |
shift 2 | |
;; | |
-c) | |
colors="$2" | |
shift 2 | |
;; | |
-d) | |
delay="$2" | |
shift 2 | |
;; | |
-f) | |
frames="$2" | |
shift 2 | |
;; | |
-r) | |
rays="$2" | |
shift 2 | |
;; | |
*) | |
break | |
;; | |
esac | |
done | |
if (( "$#" != 1 )) | |
then | |
cat <<__END__ | |
Usage: $0 [OPTIONS] FILE | |
FILE must have alpha channel, and its demension must be 128x128. | |
-b N Add N-px wide border around the base image. | |
-c N Set the preferred number of colors in the resulting image. | |
-d N Pause (N / 100) seconds before displaying the next frame. | |
-f N Generate N frames for the background animation. | |
-r N Generate N red rays for the background. | |
__END__ | |
exit 1 | |
fi | |
infile="$1" | |
if (( $colors == 256 )) | |
then | |
colors_args=() | |
else | |
colors_args=(-colors $colors) | |
fi | |
magick "$infile" -background None -gravity Center -extent 128x128 \ | |
\( +clone -alpha Extract \ | |
-morphology Dilate Disk:$border -morphology Close Disk:$border \ | |
-threshold 50% \ | |
+duplicate \ | |
-compose CopyAlpha -composite \) \ | |
+swap \ | |
-compose SrcOver -composite \ | |
,$$,infile-bordered.png | |
n="$frames" | |
for t in $(seq 0 $((n - 1))) | |
do | |
magick -size 40x1000 gradient: -rotate 90 \ | |
+distort Polar 63 \ | |
-resize 128x128 \ | |
-function Sinusoid $rays,"%[fx:360*$t/$n]" \ | |
-threshold 50% \ | |
+level-colors red,white \ | |
,$$,infile-bordered.png -composite \ | |
miff:- | |
done | magick - \ | |
+repage +dither +remap -layers OptimizeTransparency ${colors_args[@]:-} \ | |
-set delay $delay \ | |
${infile/.*/}-sunrise-b$border-c$colors-d$delay-f$frames-r$rays.gif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment