Page 1 of 1
How to batch convert entire directory of animated gifs
Posted: 2015-09-18T13:33:45-07:00
by ViPeR_930
Hi,
How do I batch resize animated gifs with imagemagick? I have this script which works for single images but I must specify both the exact image name.
convert {path to image with filename}.gif -coalesce -resize 200x200 \
-layers optimize-frame {output name}.gif
mogrify -path seems to batch process but animations all come out broken with mogrify.
Thanks!
Re: How to batch convert entire directory of animated gifs
Posted: 2015-09-18T13:48:26-07:00
by snibgo
I'd put it in a loop, so "convert" is called once per gif. When batch-converting a load of images with common elements in the name I always read from one directory and write to a different one.
Re: How to batch convert entire directory of animated gifs
Posted: 2015-09-18T14:02:15-07:00
by fmw42
Does the same command using convert mangle your animations? I tried a simple animation using mogrify and it worked fine. I did not do the optimize.
What is your IM version and platform? Can you upload your animation to dropbox.com and put the URL here, so others can test your command?
Re: How to batch convert entire directory of animated gifs
Posted: 2015-09-18T15:21:15-07:00
by ViPeR_930
Than you both for the quick replies.
snibgo, can you tell me how to change my command so it runs in a loop and outputs to a different folder?
fmw42, the convert command I have above works fine for the small batch of animated gifs I tried it with. Mogrify botched everything up. I can test more again tonight. I am using imagemagick 6.7 through SSH on my Centos server.
Re: How to batch convert entire directory of animated gifs
Posted: 2015-09-18T15:43:58-07:00
by fmw42
IM 6.7 is very old (approx 200 versions old). You would do well if you could upgrade. It could be a bug in such an old version of IM. But if you can provide one of your gif animations as requested above, I can test it in mogrify with 6.9.2.1 Q16 Mac OSX.
#create output directory if it does not exist already
Code: Select all
cd to inputdirectory
list=`ls *.gif`
echo "$list"
for img in $list; do
convert "$img" -coalesce -resize 200x200 \
-layers optimize-frame "path2outputdirectory/$img"
done
Re: How to batch convert entire directory of animated gifs
Posted: 2015-09-19T14:47:37-07:00
by ViPeR_930
Thanks for the help. I updated to 6.9 and mogrify now works for batch resizing the gifs.
Re: How to batch convert entire directory of animated gifs
Posted: 2015-09-23T11:04:58-07:00
by ViPeR_930
For a script such as this, where can I insert "nohup" command so it runs after I close the ssh connection? I put nohup at the mogrify line but it stops after completing the first directory.
Code: Select all
cd
list=`find /backup/gifs/upload/*/big -type d`
echo "list=$list"
for directory in $list; do
echo "directory=$directory"
cd $directory
nohup mogrify -path ../medium -monitor -resize '280' *.gif
cd
done