LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Bulk image format conversions with a shell script? (https://www.linuxquestions.org/questions/linux-software-2/bulk-image-format-conversions-with-a-shell-script-116212/)

infidel 11-15-2003 12:08 AM

Bulk image format conversions with a shell script?
 
Hello, all. I've been trying to come up with a way to perform bulk image format conversions. Essentially, I'd like to be able to save large quantities of JPEGs from my digital camera's memory card as TIFFs on my hard drive, without the JPEGs going through an intermediate save on the drive (and thus lossily re-compressing as they're saved). One-at-a-time conversions like this are no problem with existing image viewing/manipulation software ("Save As..."), but I typically have more then 70 images that I'd like to covert more or less at once. I don't seem to have a GUI program that will do it, and Mandrake's wacky directory structure prevents me from successfully compiling & installing anything new. It occurred to me today that since I only want to do one thing, a shell script might be a good way to do it. I have some novice (read "absolute beginner") scripting skills, but working with image formats is beyond me at the moment.

In brief, let's say that I have a bunch of files called *.jpg on /mnt/removable. I want all of them to end up as *.tif files in /home/marv/images, and I'd like to do it from the command line.

First, I assume that there have to be particular libraries available for the image format operations; can anyone tell me what they are and how to determine whether or not they're present on my system? Secondly, if the tools I need are there, would scripting this operation be a fairly simple process? If what I'm asking for here is essentially for someone to write me a program, please accept my apologies. But if it's not terribly complicated, I would greatly appreciate a gentle push in the right direction. I'm not even sure that a shell script would be the best way to do the job; but the concept, at least, seems to make sense to me. Either way, some information would be greatly appreciated. Thanks very much in advance.

Tinkster 11-15-2003 12:25 AM

The ImageMagick suite of programs
has the tool you might be looking for.

Try a
man convert
in a terminal and see whether it suites you!

Cheers,
Tink

Tinkster 11-15-2003 05:50 PM

And, working for you?


Cheers,
Tink

infidel 11-15-2003 11:41 PM

You see, I should've known before I even opened my mouth-- this is Linux we're talking about; and if there's something worth doing, chances are that somebody created the tools to do it a long time ago. ;)

ImageMagick is a fascinating set of tools, and it appears as though it will do exactly what I want (and near-infinitely more)-- if I can determine how to convert a bunch of files in one go. ImageMagick's 'convert' says it will convert an image or a sequence of images, but figuring out the command syntax for the sequence business has been the tricky part. I haven't been able to find any clear documentation on it. Single-file format conversions, yes; batch jobs, no. I've read the man page, visited the official web site, Googled it, and so on with no clear answer.

Am I correct in guessing that it's reasonable that there sould be some kind of "wildcard" arrangement or similar, where I specify that I want all .jpg files in one directory to end up as .tif files in another, without having to enter filename after filename in the command line? I'm sorry if I'm missing something completely obvious, but I can't seem to figure it out.

Thanks again...

stickman 11-16-2003 07:20 PM

I've used the convert utility from ImageMagick several times to do mass conversion. The last time was for a group that went from gif to png. My quick conversion was done with:

for FILE in *.gif
do
convert $FILE png:`echo $FILE | sed 's/.gif/.png/g'`
done

You'll probably want to do a small batch at first and check the quality of them before you get to far along. There are several convert options that will affect output quality.


All times are GMT -5. The time now is 08:30 PM.