LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-04-2004, 04:24 PM   #1
apokryphos
Member
 
Registered: Jun 2004
Distribution: openSUSE Factory
Posts: 96

Rep: Reputation: 15
Bulk change image format


I know that there's a few programs out there to convert a particular image from one filetype (i.e. GIF), to another (JPEG), like the GIMP, but are there any programs that you can mass or rather, "bulk change" the format. That is, do many at a time.

I'm generally looking to change large JPEGs to smaller jpegs, probably of lower quality. Since I have many high-quality images coming from my camera, it would be nice to have a quicker/easier way to make them smaller and put them on the Internet. Is there any program like this for Linux?

Any help would be greatly appreciated.
 
Old 09-04-2004, 04:33 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
man convert

You could use it with find or a bash-script.



Cheers,
Tink
 
Old 09-04-2004, 04:58 PM   #3
apokryphos
Member
 
Registered: Jun 2004
Distribution: openSUSE Factory
Posts: 96

Original Poster
Rep: Reputation: 15
Your help is much appreciated. I see that I can quite easily change the size of an image and change it to JPG, but quickly browsing through it, there doesn't seem to be a way to do many at a particular time. Say, wanting it to convert all the images in a folder.

Since, it seems to only allow doing one at a time, and you need ot specify a new name for it each time. Sorry for the hassle.

 
Old 09-05-2004, 12:58 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
As I said ;)

http://www.linuxquestions.org/questi...230#post534230

David (co-mod) has done a nice little script :)

Just add the resize and voila.



Cheers,
Tink

Last edited by Tinkster; 09-05-2004 at 12:59 AM.
 
Old 09-05-2004, 03:22 AM   #5
Electro
LQ Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
Re-saving JPG to a much higher compression ratio will make the picture look very blocky. If your camera has a setting to save images as tiff, you can then convert the pictures to jpeg to get better compression ratios. You can use LZW compression (lossless compression) in tiff files if you want the file size to be smaller. Though consumer digital cameras can not handle multiple shots at once when it saving pictures as tiff because both the hardware in the camera and the flash medium can not keep up.
 
Old 09-06-2004, 01:08 PM   #6
apokryphos
Member
 
Registered: Jun 2004
Distribution: openSUSE Factory
Posts: 96

Original Poster
Rep: Reputation: 15
Tinkster, sorry to bother you again, but I'm having problems. Although I really don't know what to do with the bash script ;-), it seems to me as though the settings in there are quite different -- a png with something about 16x16.

I might appear lazy, but I'm really trying to just get this working. I got together with my brother and we managed to make a C++ program to do the job, but it has a few problems, and I'd much rather have it running from a simple "convert".

So, I guess, what I'm looking for is somewhere/thing to get knowledge on bash scripts from; for the moment, just enough to be able to make this thing work. Sorry for the hassle. Any help would be greatly appreciated.

Electro, thanks for the advice, I'll try to check my camera on that later. Though, it's not that good a camera. Don't get me wrong, it does the job, but I just doubt it'll have advanced functions like that. Thanks, anyhow.
 
Old 09-06-2004, 02:12 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Not a bother at all ... :)


The Linux Documentation Project :)

There's two guides to bash there.

http://www.tldp.org/LDP/Bash-Beginne...tml/index.html

http://www.tldp.org/LDP/abs/html/index.html


As for the 16x16, that's just the NAME, not
the format. You can easily change that, too.

And since you want to make jpg into smaller
jpg you could modify the script like this, making
every jpg it finds 50% smaller along each axis.

Code:
#!/bin/bash

# Pass the dir to look in as the first argument

for file in `find $1 -iname *.jpg`; do
convert -resize 50x50% $file $file
done
In fact, since we're not renaming it or anything
we can get away with a 1-liner quite easily :)

find -iname "*.jpg" -exec convert -resize 50x50% {} {} \;

which will modify all JPGs under the current directory.
Use with extreme caution ;}


Cheers,
Tink
 
Old 09-06-2004, 03:10 PM   #8
apokryphos
Member
 
Registered: Jun 2004
Distribution: openSUSE Factory
Posts: 96

Original Poster
Rep: Reputation: 15
I'm on a real low wavelength here, sorry. When we make a bash script, I see we just run it, and it delivers a number of commands. Now I felt stupid for not guessing that. :P

Anyhow, I tried using that command that you suggested, but I had the same problem that I originally had -- not knowing how to use the -exec. The man page was a little useful, but didn't help that much.

When I type out your command in a terminal, I get this returned:
find: missing argument to `-exec'

I don't have to modify the command you suggested in any way, do I? Sorry, I promise to get it soon.
 
Old 09-06-2004, 03:19 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Code:
find -iname "*.jpg" -exec convert -resize 50x50% {} {} \;
Copy and paste that line into a terminal window...

You'll get the error message about the missing
argument if you omit the terminating \;


Cheers,
Tink
 
Old 09-06-2004, 03:43 PM   #10
apokryphos
Member
 
Registered: Jun 2004
Distribution: openSUSE Factory
Posts: 96

Original Poster
Rep: Reputation: 15
Ack, you're right. Terribly sorry. Thank you very much.
 
Old 09-06-2004, 04:13 PM   #11
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Soooo ... how about my affero? ;)



Cheers,
Tink
 
Old 09-06-2004, 04:17 PM   #12
Electro
LQ Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
In david_ross script it has little bug. If your jpeg files has spaces in their paths, it will not work. Change the script from

Code:
#!/bin/bash

# Pass the dir to look in as the first argument

for file in `find $1 -name *.png`; do
name=`echo $file | sed 's/\.png/_16x16\.xpm/'`
convert $file $name
done
to

Code:
#!/bin/bash

# Pass the dir to look in as the first argument

for file in `find $1 -name *.png`; do
name="`echo "$file" | sed 's/\.png/_16x16\.xpm/'`"
convert "$file" "$name"
done
The double quotes (") preserves the spaces and tabs. After you create the script, you will have to use chmod to make the file executable or just the command sh follow by the name of the script that you want to run.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch File for format? Bulk Formatting Beebe Solaris / OpenSolaris 2 04-12-2005 05:07 AM
Best CD image format? Cyberian Linux - Software 1 01-10-2005 01:50 PM
New Graphical Image Format gothgeek84 Programming 6 10-24-2004 08:07 AM
Bulk Image Maniulation doctorwebbox Linux - Software 1 10-20-2004 03:58 AM
Bulk image format conversions with a shell script? infidel Linux - Software 4 11-16-2003 07:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:52 PM.

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
Open Source Consulting | Domain Registration