| View previous topic :: View next topic |
| Author |
Message |
Hamking n00b


Joined: 05 Jul 2002 Posts: 67 Location: MN
|
Posted: Mon Mar 24, 2003 3:00 am Post subject: Need help resizing, and renaming a whole buttload of .jpg's |
|
|
Ok check it:
I had this totally bitchin party last weekend, and I took over 200 pics with my new digital camera. All the people at the party are yelling at me now to put up all the pics I took of the party on the net.
Ok, so I was wondering if it would be possible to come up with a script.. or some confusingly complicated(it can be simple too ) command to basicly convert all the pictures from the resolution they are at to about 50% , and then save them into another directory, with different, but repectively numerated filenames. I'm just going from .jpg to .jpg here, but scaling the image, and saving the new copy into another directory with a different file name.
Somthing like:dcp_0162.jpg, dcp_0163.jpg >>TO>> fun_party_001.jpg, fun_party_002.jpg, etc...
While at the same time scaling them down from 1800x1200 to 900x600
Could anybody help me with that???
Thanks  _________________ --Hamking  |
|
| Back to top |
|
 |
Smiler n00b

Joined: 02 Jul 2002 Posts: 10
|
Posted: Mon Mar 24, 2003 12:01 pm Post subject: |
|
|
| wouldn't some sort of thumbnail soft. do the trick ? |
|
| Back to top |
|
 |
NePhie Tux's lil' helper

Joined: 01 Sep 2002 Posts: 82
|
Posted: Mon Mar 24, 2003 12:11 pm Post subject: |
|
|
take a look at the imagemagick thingie ... it has a command "convert" which can do a shitload of stuff...and i really mean a shitload....i'm 100% sure one could come up with a command involving "convert" that does allready a part of that (the scaling part...say, do they all have to be the same res, or really something like "scale to 50%" ... i just KNOW it's gonna be easy with convert =) )
and then you wrap that command in a script wich loops all files in the directory, running that command on in with some variables (the "numbering" part)
if i'm not to lazy, i'll even look into it myself ! =) _________________ .:: $witty_statement ::. |
|
| Back to top |
|
 |
NePhie Tux's lil' helper

Joined: 01 Sep 2002 Posts: 82
|
Posted: Mon Mar 24, 2003 1:05 pm Post subject: I wasn't too lazy |
|
|
it might be not the best code around, but it's more than decent enough
very generic script that will allow you to resize any type of image in any directory to any other directory with any target "base-filename" ..check if enough parameters are given, if not it shows what it should be
| Code: |
#!/bin/bash
#test for the parameters that were given
if [ $# -eq 5 ]
then
#get us an initialized counter variable
counter=0
#loop that will go trough all files that end in .jpg in the directory
for file in $2/*.$1
do
#set the counter
counter=`expr $counter + 1`
#convert it to the given size (either res or % or ...), and save that new file in the other dir, with the other filename and counter
convert $file -resize $4 $3/$5_$counter.$1
done
else
echo "You need to call this script with 5 arguments ->"
echo "1. type of files (files must end with this) without the dot !! (ex. jpg)"
echo "2. the directory where these files are located"
echo "3. the directory where the new files should be saved"
echo "4. what the images should be resized too (ex. 50% or 800x600, ...see the convert manpage)"
echo "5. the new base-filename... this will be appended with "_" and a number (1 to ...)"
echo
echo "example --> resizer jpg /dir /other/dir 50% pics_at_half_size"
echo
echo "(ps. copy this script in /usr/bin and chmod +x it to be able to execute it like that)"
fi
|
hope you find it usefull =) (PLS keep in mind that you have to emerge imagemagick for this !! "convert" is in that package !) _________________ .:: $witty_statement ::. |
|
| Back to top |
|
 |
tukem Tux's lil' helper

Joined: 25 Jun 2002 Posts: 114 Location: Tampere, Finland
|
Posted: Mon Mar 24, 2003 5:06 pm Post subject: |
|
|
If a less flexible solution is good enough instead of that script you could use a single line version:
| Code: |
ls *.jpg | xargs -iXX convert XX -resize $4 <save path>/<prefix>XX<postfix>
|
where $4 is new image size same as in previous script. The difference in this version is that it doesn't change the original file name. It's possible to add a prefix or a postfix to the name but otherwise it's the same. |
|
| Back to top |
|
 |
|
|
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
|
|