imagemagick convert individual frame delay in gif imagemagick convert individual frame delay in gif bash bash

imagemagick convert individual frame delay in gif


So If I was approaching this problem i'd do the following ( If I understand correctly )

Given the following files:

[root@dev7 ~]# ls -lta so/total 728drwxr-xr-x   2 root root   4096 Aug 13 18:35 .dr-xr-x---. 17 root root   4096 Aug 13 18:35 ..-rw-r--r--   1 root root  18933 Aug 13 18:23 00007_1432.gif-rw-r--r--   1 root root  18594 Aug 13 18:23 00006_1432.gif-rw-r--r--   1 root root  18984 Aug 13 18:23 00005_1432.gif-rw-r--r--   1 root root  19601 Aug 13 18:23 00004_1444.gif-rw-r--r--   1 root root  19408 Aug 13 18:23 00003_1432.gif-rw-r--r--   1 root root  18632 Aug 13 18:23 00002_1552.gif-rw-r--r--   1 root root  20104 Aug 13 18:23 00001_1432.gif[root@dev7 ~]# 

My script would look like this:

#!/bin/bash -x# directory of the individual gifs_dir=/root/so/# get gifs and make sure your sort them in ordergifs=$(find $_dir -name *.gif|sort|xargs)# this is going to be the imagemagick command_CONVERT="convert "# make sure the list of gifs look correctecho $gifsfor gif in $gifs; do    # full path of each gif    full_path=$gif    # get just the name of the gif ( originally I was going to use this if everything was happing within the same directory )    name=$(echo ${gif##*/})    #echo -e "\n$name"    # Get the index    index=$(echo ${gif##*/} | cut -d\_ -f1)    #echo -e "\n$index"    # Get the delay of the current image    delay=$(echo ${gif##*/} | cut -d\_ -f2| sed "s,.gif,,")    # echo -e "\n$delay"    # add correct delay options to current gif, append to existing command   _CONVERT="${_CONVERT} -delay $delay $gif " done;# add the outpt of where you're going to put your gif_CONVERT="${_CONVERT} -loop 0 -layers Optimize /root/so/stackoverflow.gif"# show full commandecho "Convert cmd: $_CONVERT"# run it, then go get your imageeval $_CONVERT

Example of the command that gets generated:

Convert cmd: convert  -delay 1432 /root/so/00001_1432.gif  -delay 1552 /root/so/00002_1552.gif  -delay 1432 /root/so/00003_1432.gif  -delay 1444 /root/so/00004_1444.gif  -delay 1432 /root/so/00005_1432.gif  -delay 1432 /root/so/00006_1432.gif  -delay 1432 /root/so/00007_1432.gif  -layers Optimize /root/so/stackoverflow.gif

Hope this is what you're looking for.