change names using convert on multiple files

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
sparkly

change names using convert on multiple files

Post by sparkly »

Hi

I'm stuck and new to this so any help is greatly appreciated. I have written a shell script to create a large number of thumbnails (png to gif). This is working but the problem is: file names are changed with the former extension added to the file name, eg. animal.png will become animal.png.gif. How do I remove the .png?

here is the script that I am using:

for img in `ls *.png`
do
convert $img -thumbnail '300x150>' thumbs/$img
done

for img in `ls thumbs/*.png`
do
convert $img -strip $img.gif
done

cheers
sparkly

Re: change names using convert on multiple files

Post by sparkly »

found a solution that is working, added this to my script:

for f in thumbs/*.png.gif; do
base=`basename $f .png.gif`
mv -v $f thumbs/$base.gif
done

cheers,
M
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: change names using convert on multiple files

Post by anthony »

You can also use mogrify which replaces the suffix using -format
and the path using -path.... See Im exmaples
http://www.imagemagick.org/Usage/basics/#mogrify
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply