[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: using convert to batch convert



On Wed, Aug 01, 2001 at 01:14:06PM +0100, Andrew Pritchard wrote:
> Quoting "Christopher S. Swingley" <cswingle@iarc.uaf.edu>:
> > > The command I would expect to work:
> > > 
> > > convert -sample 50% *
> > 
> > Another method that I often use is:
> > 
> >     $ find ./ -name '*.gif' -exec convert -geometry 50% {} {}.png \;
> > 
> > The {}'s are replaced by the filenames that 'find' found, one at a time.
> > So this command would reduce the size of all GIF images in the current
> > (and all sub-) directories, as well as convert them to PNG files.
> 
> Correction to the above:
> Don't use -geometry to change the scale, use -sample as orginal poster said!
> 
> find ./ -name '*.gif' -exec convert -sample 50% {} {}.png \;
> 
> Otherwise it complains that it can't find the files! Took me a little while to 
> work out why it was overwriting my files with a 0 byte file :) That teach me to  
> RTFM - thank god for backups.

Yeah, that always sucks. But anyway, doesn't that end up with files 
named like 'foo.gif.png'? (Assuming the guy even wanted to convert to
.png in the first place. hm. :)  Fun with bash:

# for i in *.gif; do convert -sample 50% $i ${i%.gif}.png

...or even this, if he wants to keep gifs:  ${i%.gif}_s.gif

The former changes foo.gif to foo.png, the latter to foo_s.gif. Yay.
May need quotes if there's spaces, may need some work in ridiculous 
cases, etc. It took me forever to find this, and I was actually 
looking for it because there were things that DOS could do 
(like ren *.doc *.txt) that I couldn't figure out how to do in 
Linux / bash. :)  I think I found it in a script since man bash is a 
little incomprehensible. Take a look if you're brave. :)

Mike McGuire



Reply to: