LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   General (https://www.linuxquestions.org/questions/general-10/)
-   -   Need to resize a lot of pictures -- software recommendation needed (https://www.linuxquestions.org/questions/general-10/need-to-resize-a-lot-of-pictures-software-recommendation-needed-551143/)

ErrorBound 05-03-2007 10:35 PM

Need to resize a lot of pictures -- software recommendation needed
 
My problem is, that when pictures come off of my 7MP digital camera, the filesize is around 3MB. I have been uploading these huge files to my online gallery, which is set to resize the pictures so they are a viewable size anyway.

So, I'd like to take, say, a directory at a time full of .jpg images and reduce their size down to 50% or so before uploading. Can you recommend a software program to do this?

(This is probably easy by writing a script to use ImageMagick or something, but I'm just not into writing it myself.)

rkelsen 05-03-2007 10:39 PM

man convert

ErrorBound 05-03-2007 10:44 PM

I can't convert a whole directory at once, though....or am I missing something?

taylor_venable 05-03-2007 10:54 PM

Code:

find . -maxdepth 1 -name "*.jpg" -exec convert -resize 50% {} smaller/{} \;
Scales pictures down 50% and puts them in the directory "smaller".

rkelsen 05-03-2007 10:54 PM

Try using a 'for' loop like this:
Code:

$ for i in `ls /path/to/picture/directory/*.jpg`; do convert $i -resize 50% /path/to/output/directory/$i; done
Note the use of backticks (`) as opposed to quote marks (').

ErrorBound 05-03-2007 11:02 PM

Wow! I am in awe of your scripting skills!

ErrorBound 05-03-2007 11:05 PM

It worked, btw. Kudos to taylor and rkelsen!

rkelsen 05-03-2007 11:21 PM

Quote:

Originally Posted by ErrorBound
Wow! I am in awe of your scripting skills!

It isn't as hard as you think. These were both (TV's response and mine) fairly simple examples.

Personally, I prefer a 'for loop' for this sort of thing:
Code:

for i in list-of-files; do command $i; done
You can use it for pretty much anything which requires a command to be run on a list of files. It is worth learning how to use, IMHO.

ErrorBound 05-03-2007 11:26 PM

Well, most of the programming experience I have is in C, so that's not very useful here. I do agree that shell scripting is extremely useful and worth learning though, I just haven't had the time for it yet.

rkelsen 05-03-2007 11:54 PM

Quote:

Originally Posted by ErrorBound
Well, most of the programming experience I have is in C, so that's not very useful here.

C is Unix... ;)

jschiwal 05-04-2007 12:01 AM

Quote:

Originally Posted by rkelsen
It isn't as hard as you think. These were both (TV's response and mine) fairly simple examples.

Personally, I prefer a 'for loop' for this sort of thing

I do as well, however if the number of arguments gets to large, using a for loop will fail because the number of arguments will take up too much memory. In that case you can use "find" and "xargs":
Code:

find ./ -name "filepattern" -print0 | xargs -0 -L 1000 <command> <options>
Using print0 will use the null character to handle filenames with spaces in them.

Using a for loop, you also need to watch out for such filenames:
Code:

for i in <pattern>; do command "$i"; done

pixellany 05-04-2007 12:30 AM

I have used convert to resize folders full of pictures---without any scripting.

I seem to recall that the "convert -resize" command can take a percentage. Now I can't find the syntax.

To do multiple files in one folder: "convert -resize <parameters> *"

enine 05-04-2007 08:21 AM

What WM are you running? There is a simple download for KDE that lets you right click on one or more pictures and select a size. It simply calls imagemagick.

ErrorBound 05-06-2007 12:53 PM

Quote:

Originally Posted by enine
What WM are you running? There is a simple download for KDE that lets you right click on one or more pictures and select a size. It simply calls imagemagick.

I'm using both KDE and GNOME on different machines. The many suggestions above are working well though, and it simplifies my life just to be able to copy and paste the line into the terminal, which will work with any WM :cool:.

ErrorBound 05-06-2007 12:56 PM

Quote:

Originally Posted by rkelsen
C is Unix... ;)

Yes, C is very useful if you're into writing operating systems, but for a simple task like this, a bash one-liner will do quite well :cool:


All times are GMT -5. The time now is 07:09 PM.