bash - imagemagick convert individual frame delay in gif -


i have directory full of images want turn gif.

each file name follows pattern: <zero_padded_index>_<delay_in_milliseconds>.gif

example: 00001_1432.gif

i can create gif animation imagemagick: convert -loop 0 -delay 10 *.gif out.gif

the problem is, want each frame have different delay based on second digit in it's name.

convert -delay 0 -loop 0 *.gif output.gif  gif in *.gif;      name=${gif%.gif}     index=$(echo ${name%-*} | sed 's/0*//')     delay=${name#*-}      # 1. convert milliseconds w/e imagemagick -delay uses.     # 2. update frame @ correct index.  done; 

do incrementally build gif? or go , change them after fact? imagemagick chops not par.

so if approaching problem i'd following ( if understand correctly )

given following files:

[root@dev7 ~]# ls -lta so/ total 728 drwxr-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 this:

#!/bin/bash -x  # directory of individual gifs _dir=/root/so/  # gifs , make sure sort them in order gifs=$(find $_dir -name *.gif|sort|xargs)  # going imagemagick command _convert="convert "  # make sure list of gifs correct echo $gifs  gif in $gifs;      # full path of each gif     full_path=$gif      # name of gif ( going use if happing within same directory )     name=$(echo ${gif##*/})     #echo -e "\n$name"      # index     index=$(echo ${gif##*/} | cut -d\_ -f1)     #echo -e "\n$index"      # delay of current image     delay=$(echo ${gif##*/} | cut -d\_ -f2| sed "s,.gif,,")     # echo -e "\n$delay"      # add correct delay options current gif, append existing command    _convert="${_convert} -delay $delay $gif "   done;  # add outpt of you're going put gif _convert="${_convert} -loop 0 -layers optimize /root/so/stackoverflow.gif"  # show full command echo "convert cmd: $_convert"  # run it, go image eval $_convert 

example of command 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 you're looking for.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -