Jump to content

resizing a directory of jpgs [solved]


Recommended Posts

ok, I have a directory of jpg's. Instead of opening them up one by one in the gimp and resizing them, how do I resize a whole directory by file type? I know there's a way but I'm missing something in my command. I would imagine that this would be helpful if someone had a directory of more than 10.

 

so far, the closest I got were these 2 different commands which did the same thing. They both created a set of resized images and 2 sets of duplicates of the original size. What am I missing?

 

mogrify -size 3072x2048 -resize 800x600 +profile "*" *.jpg

convert -size 3072x2048 *.jpg -resize 800x600 *.jpg

 

[moved from Tips & Tricks by spinynorman]

Link to comment
Share on other sites

#! /bin/bash
DIRECTORY=/home/joe/images
for format in 'jpg' 'png'
do
 for image in `ls $DIRECTORY/*$format`
 do
   convert -resize 800x600 $DIRECTORY/$image
 done
done

 

that's a quick script, should work..

put it whereever, change DIRECTORY, then run it

and it *should* work, i havnt got anything to test on.

 

any bets aru upstages me with a one liner ;)

Link to comment
Share on other sites

find . -iname "*.jpg" -exec sh -c 'convert -size 800x600 "${1}" -resize 800x600 +profile "*" "${1//.jpg/-new.jpg}"' {} {} \;

 

or just

 

find . -iname "*.jpg" -exec sh -c 'convert -size 800x600 "${1}" -resize 800x600 +profile "*" "${1}"' {} {} \;

 

if you don't want to save the old one.

Link to comment
Share on other sites

Thanks for your replies guys. The only one out of the 3 that worked was this code. How would I make the new images overwrite the old ones? do I just take out the -new part?

 

 

find . -iname "*.jpg" -exec sh -c 'convert -size 800x600 "${1}" -resize 800x600 +profile "*" "${1//.jpg/-new.jpg}"' {} {} \;

Link to comment
Share on other sites

find . -iname "*.jpg" -exec sh -c 'convert -size 800x600 "${1}" -resize 800x600 +profile "*" "${1}" && echo "`basename ${1}` resized"' {} {} \;

 

This one works. I've tested it. Copy and paste it. This one will overwrite the old. All I did was add echoing some output so you can see that it is doing something.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...