FAQ   Search   Memberlist  
Profile    Log in to check your private messages    Register    Log in
resize jpg files from command line
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BLAG Forum Index -> open discussion
View previous topic :: View next topic  
Author Message
timl
PostPosted: Wed Jan 02, 2008 8:17 am    Post subject: resize jpg files from command line Reply with quote

As per the subject, I have a lot of jpg files I want to resize. I can do this from the gimp but it is a bit time consuming. Is there a command line tool I can build into a batch file to compress all the files in one go?
jebba
PostPosted: Wed Jan 02, 2008 8:22 am    Post subject: Reply with quote

Code:
convert -resize 1024\>x768 foo.jpg foo-small.jpg


Or to do a whole directory, you could do a script something like:

Code:
#!/bin/sh
for i in *.jpg
do echo "converting $i"
   convert -resize 1024\>x768 \
   $i `basename $i .jpg`-small.jpg
done



Last edited by jebba on Thu Jan 03, 2008 8:37 am; edited 1 time in total
saddletramp
PostPosted: Wed Jan 02, 2008 12:53 pm    Post subject: Reply with quote

hey jebba,
where did you come up with some concoction like that? LOL

that's exactly what i'm talking about with the command line. who in their right mind, would know some gibberish like that? no, normal joe blow user would EVER figure that out!!

extraspecialbitter
PostPosted: Wed Jan 02, 2008 1:43 pm    Post subject: Reply with quote

saddletramp wrote:
that's exactly what i'm talking about with the command line. who in their right mind, would know some gibberish like that? no, normal joe blow user would EVER figure that out!!


saddletramp - for some of us normal joes, it's our job to both figure out and create command line gibberish when there's no available GUI to do the trick. Jebba's example is a fairly simple but powerful 5-line shell script that will resize every JPG file in a directory. It's the stock and trade of Joe Admin.

berkbw
PostPosted: Wed Jan 02, 2008 1:43 pm    Post subject: Reply with quote

Try "apropos resize"
saddletramp
PostPosted: Wed Jan 02, 2008 2:30 pm    Post subject: Reply with quote

extraspecialbitter wrote:
saddletramp wrote:
that's exactly what i'm talking about with the command line. who in their right mind, would know some gibberish like that? no, normal joe blow user would EVER figure that out!!


saddletramp - for some of us normal joes, it's our job to both figure out and create command line gibberish when there's no available GUI to do the trick. Jebba's example is a fairly simple but powerful 5-line shell script that will resize every JPG file in a directory. It's the stock and trade of Joe Admin.


i apologise for talking about it like that, but it simply blows me away. i couldn't do that "gibberish" if i wanted to, i don't think. will probably take more years to learn that i have left on earth! i have enough headaches fixing everybody else's stuff around here in the windows world, along with my real job. i'm just here to play in linux.

so, from here on in, when ever you hear me talk about the command line, just blow it off! i respect it and fear it!! but, do expect me to be asking, when necessary, what the heck is the code for whatever i may be trying to wreck!!

noldrin
PostPosted: Wed Jan 02, 2008 3:41 pm    Post subject: Reply with quote

saddletramp wrote:
i apologise for talking about it like that, but it simply blows me away. i couldn't do that "gibberish" if i wanted to, i don't think. will probably take more years to learn that i have left on earth! i have enough headaches fixing everybody else's stuff around here in the windows world, along with my real job. i'm just here to play in linux.

so, from here on in, when ever you hear me talk about the command line, just blow it off! i respect it and fear it!! but, do expect me to be asking, when necessary, what the heck is the code for whatever i may be trying to wreck!!


Dude, that's like saying some Asian language is gibberish just because you don't know how to read it. Once you learn the language, it makes much more sense. When you need to learn something new, you can read the documentation on how to use it.

saddletramp
PostPosted: Wed Jan 02, 2008 6:00 pm    Post subject: Reply with quote

"Dude, that's like saying some Asian language is gibberish just because you don't know how to read it."

Dude,
that's EXACTLY what i'm saying!! LOL

jebba
PostPosted: Wed Jan 02, 2008 6:49 pm    Post subject: Reply with quote

saddletramp wrote:
hey jebba,
where did you come up with some concoction like that? LOL

that's exactly what i'm talking about with the command line. who in their right mind, would know some gibberish like that? no, normal joe blow user would EVER figure that out!!


If you want to resize, say, five thousand images you can do it with that wee little script, hit enter and go away until it's done. Imagine trying to do that with gimp or photoshop!

Since the system is so well documented you can just type `man <command>` and read all the documentation about it. Depending on your workflow a few simple commands can really speed up what you do....

-Jeff

berkbw
PostPosted: Wed Jan 02, 2008 7:05 pm    Post subject: Reply with quote

and better than that, you don't have to wait for it.
Jason
PostPosted: Thu Jan 03, 2008 7:49 am    Post subject: Reply with quote

What we need is little bits like that documented Jeff :) I didn't actually know that either despite knowing a fair bit of command line work. Never crossed my mind the command line would handle images. Nice job.

Photoshop CS3 does it btw automatically saving as any file type, resolution, size, etc. Just murders your memory for like half an hour. And it isn't free and nowhere near as quick evidently.

I am going to look for a nice easy way to rip all the code out of these forums to stick somewhere either on BLAG site or wiki though my wiki skills are a bit off the mark.

timl
PostPosted: Thu Jan 03, 2008 8:02 am    Post subject: Reply with quote

Jebba, good stuff. Like all others I wish I could come up with something as smart & to the point. I never did get by head around command line scripts. One thing though, I needed to change "$i.jpg" to "$i" as the ".jpg" is already part of the extracted symbol.

Cheers

jebba
PostPosted: Thu Jan 03, 2008 8:38 am    Post subject: Reply with quote

timl wrote:
I needed to change "$i.jpg" to "$i" as the ".jpg" is already part of the extracted symbol.


ah thx for pointing that out. fixed above.

john maclean
PostPosted: Thu Jan 03, 2008 10:41 am    Post subject: Reply with quote

Slightly off topic but here's a script for mass renaming files by extension. Feed something like jpg and it will remove all the spaces, replacing them with foo_bar_la_de_dah.jpg"
Code:
#! /bin/bash
# -*- mode: shell -*-
# nulspaces.sh - a script to remove spaces from files
# for safety we ask for file extension before we operate
# date Sun Jan  9 02:19:14 GMT 2005
# todo
# file permissions, verbosity, confirmations, changing dirnames as well
# jayeola :*cough*: gmail :*cough*: com
# Free Software Foundation, Inc.

read -p "extension :  " EXT
find /home/$USER/ -iname "* *"$EXT"" | while read line
do
    BN=`basename "$line"  |sed -e 's/ /_/g'`
    DN=`dirname "$line"`
    mv  "$line"   "$DN"/"$BN"| sh -s
    echo "$BN" moved
done


_________________
BLAG 'em up!
saddletramp
PostPosted: Thu Jan 03, 2008 1:54 pm    Post subject: Reply with quote

jebba wrote:
timl wrote:
I needed to change "$i.jpg" to "$i" as the ".jpg" is already part of the extracted symbol.


ah thx for pointing that out. fixed above.


see? and as lousy a typist as i am!! to easy to make a mistake and possibly really mess something up.

Display posts from previous:   
Post new topic   Reply to topic    BLAG Forum Index -> open discussion Goto page 1, 2  Next
Page 1 of 2

Protected by Anti-Spam ACP