LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-26-2010, 04:30 PM   #1
McDuck
LQ Newbie
 
Registered: Apr 2010
Posts: 2

Rep: Reputation: 0
Image Magick - Resize pictures in all subdirectories


Heey guys,

I'd like to resize a lot of pictures which are in subdirectories. all the pictures are stored in /home/username/Pictures

With Image Magick I can resize a single picture by:
Code:
convert -size 1024 somefile.jpg -resize 1024 ./newsize1024/somefile1024.jpg
But now I want to resize all the pictures in current and all subdirectories without doing it manually.

Can u guys help me out with a command, bash script, c code or some other code? (i prefer the easiest way)

thnx in advance!
McDuck

Additional:
can the solution contain the solution to resize the picture to the highest dimension?
currently:
convert (from the image magick package) has a -resize option. this option can only resize to the maximum width, eg:
Code:
convert -resize 1024 somefile.jpg
with picture size: 2048x1572 to 1024x786
but with picture size: 1572x2048 to 1024x1334

desired:
which would output: 1024x786 and 786x1024
 
Old 04-26-2010, 04:47 PM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 7,775

Rep: Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741Reputation: 741
Let me mention a typo - 1024x768 is the usual size.

Unless you have a bundle of pictures, you might be quicker doing it by hand.

use find (man find) which descends subdirs [ find <options> |xargs do stuff

and go chase gimp scripts (script-fu) to see if they can automate some of the messing.
 
Old 04-26-2010, 05:00 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by McDuck View Post
can the solution contain the solution to resize the picture to the highest dimension?
Yes. Specify both dimensions for -resize:
Code:
convert -resize 1024x1024 input.jpg output.jpg
in this way aspect ratio is still preserved, but you will get the desired size:
Code:
2048x1572 --> 1024x786
1572x2048 --> 786x1024
Regarding the recursion, follow the suggestion by business_kid and try find out. A simple while loop in bash should do the trick.
 
Old 04-26-2010, 05:10 PM   #4
McDuck
LQ Newbie
 
Registered: Apr 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Thnx for the fast replies!

Quote:
Originally Posted by business_kid View Post
Let me mention a typo - 1024x768 is the usual size.
geh3

Quote:
Originally Posted by business_kid View Post
Unless you have a bundle of pictures, you might be quicker doing it by hand.
Thats exactly my problem ;-)

Quote:
Originally Posted by business_kid View Post
use find (man find) which descends subdirs [ find <options> |xargs do stuff
I tried that option, but i wasnt being able convert working with find. i got stuck the point that convert does need 2 filename. 1 original, and 1 resized.

Quote:
Originally Posted by colucix View Post
Yes. Specify both dimensions for -resize:
Code:
convert -resize 1024x1024 input.jpg output.jpg
in this way aspect ratio is still preserved, but you will get the desired size:
Code:
2048x1572 --> 1024x786
1572x2048 --> 786x1024
Exactly what i was looking for =) prob didnt understood the man right.

Quote:
Originally Posted by colucix View Post
Regarding the recursion, follow the suggestion by business_kid and try find out. A simple while loop in bash should do the trick.
bash with recursion?
 
Old 04-26-2010, 05:29 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by McDuck View Post
bash with recursion?
I mean to descend recursively into a directory tree. Let me do an example:
Code:
while read file
do
  convert -resize 1024x1024 "$file" "${file/.jpg/1024.jpg}
done < <(find . -name \*.jpg)
This uses process substitution to feed the while loop (you can refine the find comman to match your search criteria) and substring replacement in parameter substitution to build the name of the output file.

This creates the new file in the same directory as the original file. If you want all the new files in one specific location (as in your example) first you have to extract the file name. Here is an example using substring removal:
Code:
while read file
do
  oufile="${file##*/}"
  convert -resize 1024x1024 "$file" "./newsize1024/${oufile/.jpg/1024.jpg}"
done < <(find command here)
Ah, just noticed this is your first post here... welcome to LinuxQuestions!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
image magick install help needed DotHQ Linux - Software 6 01-20-2009 10:02 AM
Image magick help! disruptive Programming 1 02-13-2008 07:54 PM
How to uninstall old image magick? centosfan Linux - Server 4 12-22-2007 10:09 AM
icewm & image magick fourcs Linux - Software 1 12-09-2005 06:44 AM
Image::Magick for FC4 AMD64 rwhite7890 Linux - Software 7 07-07-2005 08:19 AM


All times are GMT -5. The time now is 06:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration