Bulk image format conversions with a shell script?
Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.