convert pdf generates corrupt image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
maqe
Posts: 17
Joined: 2017-06-18T02:21:18-07:00
Authentication code: 1151

convert pdf generates corrupt image

Post by maqe »

I'm using ImageMagick with a docker container. My image looks like this.

FROM alpine:latest
LABEL maintainer "Jessie Frazelle <jess@linux.com>"

RUN apk --no-cache add \
imagemagick \
ghostscript \
--update curl

CMD [ "echo", "Use one of the following commands [ animate | compare | composite | conjure | convert | display | identify | import | mogrify | montage | stream ]" ]

The version of ImageMagick is:

Version: ImageMagick 7.0.5-10 Q16 x86_64 2017-06-05 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher HDRI Modules
Delegates (built-in): fontconfig freetype gslib jng jpeg lcms ltdl png ps tiff webp xml zlib

When I run the following command ImageMagick produces a corrupt image.

docker run imagemagick convert -verbose http://www.pdf995.com/samples/pdf.pdf[0] - > foo.jpg
/tmp/magick-1-JjeGtapAEMe1 PNG 612x792 612x792+0+0 8-bit sRGB 60787B 0.020u 0:00.020
/tmp/magick-1et9Ro9BFOGOh PDF 612x792 612x792+0+0 16-bit sRGB 60787B 0.000u 0:00.000
http://www.pdf995.com/samples/pdf.pdf[0]=>pdf.pdf PDF 612x792 612x792+0+0 16-bit sRGB 60787B 0.000u 0:00.000

When I try to open the image it produces I get an error that it's corrupt or damaged?

This is a link to the converted image: https://d26dzxoao6i3hh.cloudfront.net/i ... 3I/foo.jpg
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert pdf generates corrupt image

Post by snibgo »

maqe wrote:convert -verbose http://www.pdf995.com/samples/pdf.pdf[0] - > foo.jpg
Using "-" as the output, you are not telling IM what format to use. So IM uses the same as the input format, in this case PDF. You write that to a file called "foo.jpg", but this isn't JPEG format.

The command you want is:

Code: Select all

convert -verbose http://www.pdf995.com/samples/pdf.pdf[0] foo.jpg
snibgo's IM pages: im.snibgo.com
maqe
Posts: 17
Joined: 2017-06-18T02:21:18-07:00
Authentication code: 1151

Re: convert pdf generates corrupt image

Post by maqe »

I use the pipe "-" to output the image to stdout. How can I output to stdout and still tell IM to use jpeg format?
maqe
Posts: 17
Joined: 2017-06-18T02:21:18-07:00
Authentication code: 1151

Re: convert pdf generates corrupt image

Post by maqe »

It seems like jpeg:- works if I want to output the image to stdout. Is it the recommended way to it?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert pdf generates corrupt image

Post by snibgo »

Yes. Prefix the output with the required format, eg:

Code: Select all

convert -verbose http://www.pdf995.com/samples/pdf.pdf[0] JPG:-
snibgo's IM pages: im.snibgo.com
Post Reply