LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using convert from imagemagick package to convert multiple jpg files (http://www.linuxquestions.org/questions/linux-newbie-8/using-convert-from-imagemagick-package-to-convert-multiple-jpg-files-820539/)

janis_169 07-18-2010 10:44 AM

Using convert from imagemagick package to convert multiple jpg files
 
Hi!!!
I'm trying to use convert, I have installed the imagemagick.
I use this line:
convert *.jpg test.pdf
but I'm only able to convert to pdf 1 single jpg file, not multiple files at once. When there's more than one file, I get the following error:
Segmentation fault
Could anybody help me??
Thanks a lot, I'm really new at this
Janis

Bruce Hill 07-18-2010 11:02 AM

Not sure about any other method, but can you test this bash one liner,
maybe copying your files to a directory just to test this. So if it does
not work, you still have your original files as they are now.
Code:

for i in *.jpg; do convert "$i" "`basename "$i" .jpg`".pdf; done
In your example above, you would be asking for every file with .jpg as an
extension to be converted to one pdf file named test.pdf

Whereas "convert *.jpg *.pdf" would convert every file ending in .jpg to
it's corresponding name ending in .pdf -- either try this last example or
the bash one liner above. Either way, use a test directory with copied files
so you don't accidentally hose the originals.

pixellany 07-18-2010 11:02 AM

You command tries to convert all files ending in ".jpg" to "test.jpg". I don't think that's what you want.

Suppose you have 3 files:
peter.jpg
paul.jpg
mary.jpg

I would think you would want:
peter.pdf
paul.pdf
mary.pdf

If that's correct, then something like this should work (not tested):

Code:

for file in *jpg; do
    convert $name $(sed 's/\.jpg//' $name).pdf
done

Regardless, please confirm the "before and after" result you are looking for.

pixellany 07-18-2010 11:04 AM

((Bruce and I posted at the same time---as far as I can tell, both solutions will work.))

janis_169 07-18-2010 03:28 PM

Hi, Bruce and Pixellany, I tried Bruce's bash line, and I succeeded to obtain each of the jpgs as a pdf files. As they belong to a book (I'm talking of about 1000 jpg files, and now 1000 pdf files), I would like to merge them together. How can I do that???
Thank you very much, again
Janis

pixellany 07-18-2010 04:22 PM

I think if you are merging a bunch of jpgs, pdfs, etc. you need to say something about how they are assembled.

For example, what is the size of the pictures and what it the page size that you want in the finished document?

Have you looked thru the ImageMagick documentation here?
http://www.imagemagick.org/script/index.php
Also search in Google for--eg--"pdf tools Linux"


All times are GMT -5. The time now is 10:00 PM.