LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 04-03-2008, 04:21 AM   #1
zeltak
Member
 
Registered: Feb 2006
Distribution: kubuntu dapper
Posts: 61

Rep: Reputation: 15
need help with imagemagic....batch resize


Hi all

I am moding a icon theme (will post it once finished) to my liking. I have a Q for the command line gurus. I have edited the icon theme for the 128 size. the 128 folder has 6 directories with pngs in them. i want to use image magic to resize the whole directory to 64x64 size while keeping the folder structure, is it possible?

thx alot in advance

Zeltak
 
Old 04-03-2008, 04:33 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,689

Rep: Reputation: 286Reputation: 286Reputation: 286
Nested for loops might work. Something like:
Code:
#!/bin/bash
for i in /path/to/top/leveŀ/folder/*; do
       for i in *.png; do
            imagemagick resize command
       done;
 done
 
Old 04-03-2008, 04:46 AM   #3
zeltak
Member
 
Registered: Feb 2006
Distribution: kubuntu dapper
Posts: 61

Original Poster
Rep: Reputation: 15
Hi

Thx alot for the answer, but i am pretty new to the whole command line thing . So far ive created a txt file with this



#!/bin/bash
for i in /media/thd/DL-Web downloads/scale/128x128/; do
for i in *.png; do
mogrify -resize 16x16 *.png
done;
done

but it dosent seem to work. am i totally off here?



sorry for the ignorance

Zeltak

Last edited by zeltak; 04-03-2008 at 04:56 AM.
 
Old 04-03-2008, 10:34 AM   #4
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,689

Rep: Reputation: 286Reputation: 286Reputation: 286
Now that you have created the shell script (the text file containing the code), you must make it executable before you can use it.

In a console, cd (the command to change directory) to the directory containing the script. Issue the command ls -l <scriptname>, where <scriptname> is the name of your script. ls -l shows a long lising which includes the permissions for owner/group/others (rw-rw-r--, or something similar. The dash is the place for the x letter, which indicates executable (for a file) and permission to enter (for a folder).

To make your script executable, issue the command chmod +x <scriptname> (to give executable to the owner, members of the group,and all others. Issue the command chmod u+x <scriptname> to give execute permission to the owner only.

Then, to execute the script, ./<scriptname>. The leading ./ means "in this directory".
Or, from anywhere in the directory tree, just give the full path to the executable to run it: /media/thd/DL-Web downloads/scale/128x128/<scriptname>.

Note that you may use the script in your own home folder without restriction. To use it in a folder normally restricted for users, you wil have to run the script as root.
 
Old 04-03-2008, 12:29 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
Quote:
but it dosent seem to work. am i totally off here?

sorry for the ignorance
The issue is most likely with the path-name with
the space in it. Always a bad idea.

Code:
find /media/thd/DL-Web\ downloads/scale/128x128/ -type f -iname \*png -exec mogrify resize 64x64 {} \;



Cheers,
Tink

Last edited by Tinkster; 04-03-2008 at 12:31 PM.
 
Old 04-03-2008, 12:33 PM   #6
kotnik
Member
 
Registered: Nov 2004
Location: Novi Sad, Serbia
Distribution: Debian, Slackware, Gentoo, openSuSE
Posts: 254

Rep: Reputation: 31
If your icon files have spaces in its names, then use modified Tink's oneliner:

Code:
find /media/thd/DL-Web\ downloads/scale/128x128/ -type f -iname \*png -exec mogrify resize 64x64 "{}" \;
 
Old 04-04-2008, 01:05 AM   #7
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,242
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
perhaps you mean something like this?
Code:
#!/bin/bash
for i in /media/thd/DL-Web downloads/scale/128x128/*.png; do
	mogrify -resize 16x16 "${i}"
done

Last edited by konsolebox; 04-04-2008 at 01:06 AM. Reason: forgot to add double quotes around ${i}
 
Old 04-04-2008, 11:59 PM   #8
zeltak
Member
 
Registered: Feb 2006
Distribution: kubuntu dapper
Posts: 61

Original Poster
Rep: Reputation: 15
Hi

thank you all for your reply! konsolebox your suggestion did the trick exactly!

thanks again, you guys saved me a ton of time!

Zeltak
 
Old 04-05-2008, 09:34 PM   #9
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,242
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
no prob. you're welcome... but i wonder how the code worked.. the space should have a backslash before it:
Code:
#!/bin/bash
for i in /media/thd/DL-Web\ downloads/scale/128x128/*.png; do
	mogrify -resize 16x16 "${i}"
done
 
Old 04-05-2008, 11:47 PM   #10
zeltak
Member
 
Registered: Feb 2006
Distribution: kubuntu dapper
Posts: 61

Original Poster
Rep: Reputation: 15
I changed the directory ;-)

thx again

Zeltak
 
  


Reply

Tags
resize


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
batch resize in digikam muddywaters Linux - Software 2 06-07-2006 10:20 PM
Install ImageMagic notooth Linux - Software 12 04-24-2005 04:10 PM
ImageMagic mickeyboa Fedora 3 10-07-2004 07:05 PM
batch image resize and compression Darkfalz Linux - Software 3 08-01-2004 02:08 AM
ImageMagic compile problems with libdps silversky Slackware 2 01-25-2004 08:06 PM


All times are GMT -5. The time now is 11:35 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration