Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Recipe: resize batch with Imagemagick
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
Treovo
Tux's lil' helper
Tux's lil' helper


Joined: 30 Mar 2004
Posts: 88

PostPosted: Wed Jul 06, 2005 6:43 pm    Post subject: Recipe: resize batch with Imagemagick Reply with quote

How to resize the pictures matching some criteria in the current directory in 4 lines.

Code:

#!/bin/sh

for picture in `find . -name '*.JPG'`
do
  convert $picture -resize 60% $img
done


Copy the lines above in a file and save it. Run it using
Code:
sh /path/to/the/file
.
The script will look for files matching the search criteria and resize them using convert.

You can adjust the ration or use other command line tools part of Imagemagick like mogrify.
The scripting capabilities of Imagemagick make it the perfect tool for the job.

This is nothing more than my 2 cents to the community, but as those 4 lines have saved the novice that I am a LOT of time...so I thought I'd share it :)
_________________
.: Free your mind and your ass will follow :.
Back to top
View user's profile Send private message
bgradid
Apprentice
Apprentice


Joined: 21 Mar 2005
Posts: 162

PostPosted: Wed Jul 06, 2005 6:55 pm    Post subject: Reply with quote

i'd heard of the imagemagik library before, but, wow, I didn't know it was this simple to use

many thanks! :D
Back to top
View user's profile Send private message
Treovo
Tux's lil' helper
Tux's lil' helper


Joined: 30 Mar 2004
Posts: 88

PostPosted: Mon Aug 29, 2005 7:28 pm    Post subject: Reply with quote

For an obscure reason (well I did not take the time to find out why...) the above script stopped to work.
As a result I extended it a bit to better suit my needs. This version will determine the orientation of the image and resize it accordingly. You can replace the size of the image by any other that suits you.

Code:

#!/bin/sh

for picture in `find ./ -name '*.JPG'`
do
W=`identify -format "%w" $picture`
H=`identify -format "%h" $picture`
echo $picture
echo $W
echo $H
   if [ "$W" -gt "$H" ]
   then
        mogrify $picture -resize 768x576 $picture
     else
        mogrify $picture -resize 576x768 $picture
     fi
done

_________________
.: Free your mind and your ass will follow :.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum