Discussion:
imagemagick convert PDF to JPG/PNG
Avi Kouzi
2008-04-09 12:36:38 UTC
Permalink
Hello all,

I have been trying to convert a PDF file to JPG or to PNG.

I just updated to the latest versions via debian APT.
I also have ghostscript installed and everything seems to be working.

It seems that there is a problem in my understanding of how things work,
while I issue the following command :

convert 1.pdf 1.png OR convert 1.pdf 1.jpg

I get the output files with a distorted colors and edeges and I can't
seem to find a way to fix this.
I believe there is an existing solution to this problem, but I couldn't
find it anywhere.

I attached three files, a correctly generated JPG file (via
acrobat/photoshop), and the two damaged file outputed via imagemagick
convert.
If you could help me and point me to the right direction I would be very
greatfull.

Thanks!
Avi.
Florian Groothuis
2008-04-09 13:26:01 UTC
Permalink
I'm trying to use ImageMagick from within an application written in
Magic (V9.4sp6b). I chose ImageMagick because it offers
COM+-compatibility. When I open the COM-interface in Magic (CallCom) I
have to fill arguments, return values and so on.

* I installed ImageMagick properly, it works on the command line
and the Type Library is selectable in the list
* I created and virtual (type=OLE, var=A, library=ImageMagick)
* I create a new line, CallCom, Object=A,
option=CallMethod,Method=Identify, Arguments=???, ReturnValue=???
* The problems are in the arguments and the return value. The
argument is of (external) type VT_Variant (R,A), Direction In/Out and
optional.
* What do I send as argument? I tried: 'C:\tmp\image.jpg'
,File2Blb('C:\tmp\image.jpg'), VariantCreate(8200,'C:\tmp\image.jpg').
In this last case I get no error but the return value is empty according
to the Flow Monitor.

The Return Value is another issue. Type is VT_Variant and is also
optional.

* What is returned? I used an Virtual, Alpha255 as ReturnVariable,
but it stays empty.The Monitor reports "Returned Value:{VT_EMPTY}"
* I used a blob as well. Same results.

The image exists and on the command line it works fine.
Ross Presser
2008-04-09 18:06:31 UTC
Permalink
This mailing list doesn't generally support attachments; in any case your
attachments did not arrive with your message. Please post links where we may
download them.
Post by Avi Kouzi
Hello all,
I have been trying to convert a PDF file to JPG or to PNG.
I just updated to the latest versions via debian APT.
I also have ghostscript installed and everything seems to be working.
It seems that there is a problem in my understanding of how things work,
convert 1.pdf 1.png OR convert 1.pdf 1.jpg
I get the output files with a distorted colors and edeges and I can't seem
to find a way to fix this.
I believe there is an existing solution to this problem, but I couldn't
find it anywhere.
I attached three files, a correctly generated JPG file (via
acrobat/photoshop), and the two damaged file outputed via imagemagick
convert.
If you could help me and point me to the right direction I would be very
greatfull.
Thanks!
Avi.
_______________________________________________
Magick-users mailing list
http://studio.imagemagick.org/mailman/listinfo/magick-users
Avi Kouzi
2008-04-10 01:41:40 UTC
Permalink
Sorry, here are the links :

Loading Image...
Loading Image...
Loading Image...

It seems that the PDF was in CMYK, when I asked for the designer to
convert it to RGB, the colors were slightly more consistent ( as you can
see in Loading Image...
but there is still a noticeable change of colors) , there is also this
problem with the edges that are not sharp and straight as it should be.

I appreciate all the help,
Avi.
Post by Ross Presser
This mailing list doesn't generally support attachments; in any case your
attachments did not arrive with your message. Please post links where we may
download them.
Post by Avi Kouzi
Hello all,
I have been trying to convert a PDF file to JPG or to PNG.
I just updated to the latest versions via debian APT.
I also have ghostscript installed and everything seems to be working.
It seems that there is a problem in my understanding of how things work,
convert 1.pdf 1.png OR convert 1.pdf 1.jpg
I get the output files with a distorted colors and edeges and I can't seem
to find a way to fix this.
I believe there is an existing solution to this problem, but I couldn't
find it anywhere.
I attached three files, a correctly generated JPG file (via
acrobat/photoshop), and the two damaged file outputed via imagemagick
convert.
If you could help me and point me to the right direction I would be very
greatfull.
Thanks!
Avi.
_______________________________________________
Magick-users mailing list
http://studio.imagemagick.org/mailman/listinfo/magick-users
_______________________________________________
Magick-users mailing list
http://studio.imagemagick.org/mailman/listinfo/magick-users
d***@imagemagick.org
2008-04-10 01:49:54 UTC
Permalink
Post by Avi Kouzi
It seems that the PDF was in CMYK
Did you try

convert -colorspace rgb image.pdf image.jpg

or

convert image.pdf -profile USWebCoatedSWOP.icc -profile sRGB.icm image.jpg

Both methods are the suitable for properly converting a CMYK PDF to RGB JPEG.
Avi Kouzi
2008-04-10 01:57:23 UTC
Permalink
I already tried the first one, it gives out pretty much the same results
as converted.jpg, the second one wouldn't run since I don't have those
ICM/ICC files (nowhere to be found on my filesystem).

Also, now that I have the RGB PDF, it is still not helping much (as
there is still a slight color diffrence and the edges issue).
Post by d***@imagemagick.org
Post by Avi Kouzi
It seems that the PDF was in CMYK
Did you try
convert -colorspace rgb image.pdf image.jpg
or
convert image.pdf -profile USWebCoatedSWOP.icc -profile sRGB.icm image.jpg
Both methods are the suitable for properly converting a CMYK PDF to RGB JPEG.
Ross Presser
2008-04-10 05:37:13 UTC
Permalink
The edge noise appears to me to be standard JPEG artifacting. If your
original PDF stored the image using DCT encoding within the PDF, then
the conversion process from PDF to bitmap back to JPEG is unavoidably
going to add more artifacting, because of JPEG being a lossy format.
It seems likely that this doesn't happen when you use Photoshop as the
intermediary because Photoshop might be pulling the actual DCT encoded
data from the PDF and wrapping it in the JPEG file format -- rather
than rasterizing and re-encoding, as ImageMagick must do, since it
doesn't itself know about the PDF file format but relies on a
delegate.

I don't see any way to completely eliminate this and still have a JPEG
final output.

The PNG you posted doesn't show edge artifacts that I can see. It has
markedly different colors but that is because it started from the CMYK
pdf. Are the colors right if you start from the RGB pdf? If they are
not, then the solution would be to have Ghostscript (the PDF delegate)
use the right ICC profile that matches what is in the PDF.
Post by Avi Kouzi
I already tried the first one, it gives out pretty much the same results
as converted.jpg, the second one wouldn't run since I don't have those
ICM/ICC files (nowhere to be found on my filesystem).
Also, now that I have the RGB PDF, it is still not helping much (as
there is still a slight color diffrence and the edges issue).
Post by d***@imagemagick.org
Post by Avi Kouzi
It seems that the PDF was in CMYK
Did you try
convert -colorspace rgb image.pdf image.jpg
or
convert image.pdf -profile USWebCoatedSWOP.icc -profile sRGB.icm
image.jpg
Post by d***@imagemagick.org
Both methods are the suitable for properly converting a CMYK PDF to RGB
JPEG.
_______________________________________________
Magick-users mailing list
http://studio.imagemagick.org/mailman/listinfo/magick-users
Avi Kouzi
2008-04-10 14:07:59 UTC
Permalink
here (both ACDSEE and Firefox) shows the PNG file with the same result
as the JPEG does (with edge artifacts).

Using the RGB version of the PDF - there are still slight color
diffrences but not as much as with the CMYK version.
Question: why wouldn't the CMYK version work correctly in the first
place using the -colorspace and such? (just like converting the CMYK to
RGB in acrobat, or any other photo editing software for that matter?)

In regards to what you say about the DCT encoding, is it correct for me
to assume I should be using PNG instead of JPEG?
And is there no way to tell imagemagick do the same trick photoshop
does? (wrapping the DCT encoding inside the JPEG instead of rasterizing
and re-encoding?)

I just need it to work correctly, does not really matter if the source
file is CMYK or RGB and if the output file is JPEG or PNG.
Perhaps a different software can help resolve this issue? maybe
converting the PDF to some middle-man format that will convert to JPEG
or PNG?

I appreciate the help,
Avi.
Post by Ross Presser
The edge noise appears to me to be standard JPEG artifacting. If your
original PDF stored the image using DCT encoding within the PDF, then
the conversion process from PDF to bitmap back to JPEG is unavoidably
going to add more artifacting, because of JPEG being a lossy format.
It seems likely that this doesn't happen when you use Photoshop as the
intermediary because Photoshop might be pulling the actual DCT encoded
data from the PDF and wrapping it in the JPEG file format -- rather
than rasterizing and re-encoding, as ImageMagick must do, since it
doesn't itself know about the PDF file format but relies on a
delegate.
I don't see any way to completely eliminate this and still have a JPEG
final output.
The PNG you posted doesn't show edge artifacts that I can see. It has
markedly different colors but that is because it started from the CMYK
pdf. Are the colors right if you start from the RGB pdf? If they are
not, then the solution would be to have Ghostscript (the PDF delegate)
use the right ICC profile that matches what is in the PDF.
Post by Avi Kouzi
I already tried the first one, it gives out pretty much the same results
as converted.jpg, the second one wouldn't run since I don't have those
ICM/ICC files (nowhere to be found on my filesystem).
Also, now that I have the RGB PDF, it is still not helping much (as
there is still a slight color diffrence and the edges issue).
Post by d***@imagemagick.org
Post by Avi Kouzi
It seems that the PDF was in CMYK
Did you try
convert -colorspace rgb image.pdf image.jpg
or
convert image.pdf -profile USWebCoatedSWOP.icc -profile sRGB.icm
image.jpg
Post by d***@imagemagick.org
Both methods are the suitable for properly converting a CMYK PDF to RGB
JPEG.
_______________________________________________
Magick-users mailing list
http://studio.imagemagick.org/mailman/listinfo/magick-users
Avi Kouzi
2008-04-10 15:02:17 UTC
Permalink
I just went throught some old posts at Magick-bugs, and I saw someone
stating that pdftoppm utility (xpdf package) works well.
I tried converting the PDF to PPM first, only then using convert, it
seems to get me the exact right colors(using the RGB PDF only), and much
better looking edges, however still not perfect as the correct jpg (by
acrobat/photoshop) shows.

the result I recieved can be viewed at :
Loading Image...

Avi.
Post by Avi Kouzi
here (both ACDSEE and Firefox) shows the PNG file with the same result
as the JPEG does (with edge artifacts).
Using the RGB version of the PDF - there are still slight color
diffrences but not as much as with the CMYK version.
Question: why wouldn't the CMYK version work correctly in the first
place using the -colorspace and such? (just like converting the CMYK
to RGB in acrobat, or any other photo editing software for that matter?)
In regards to what you say about the DCT encoding, is it correct for
me to assume I should be using PNG instead of JPEG?
And is there no way to tell imagemagick do the same trick photoshop
does? (wrapping the DCT encoding inside the JPEG instead of
rasterizing and re-encoding?)
I just need it to work correctly, does not really matter if the source
file is CMYK or RGB and if the output file is JPEG or PNG.
Perhaps a different software can help resolve this issue? maybe
converting the PDF to some middle-man format that will convert to JPEG
or PNG?
I appreciate the help,
Avi.
Post by Ross Presser
The edge noise appears to me to be standard JPEG artifacting. If your
original PDF stored the image using DCT encoding within the PDF, then
the conversion process from PDF to bitmap back to JPEG is unavoidably
going to add more artifacting, because of JPEG being a lossy format.
It seems likely that this doesn't happen when you use Photoshop as the
intermediary because Photoshop might be pulling the actual DCT encoded
data from the PDF and wrapping it in the JPEG file format -- rather
than rasterizing and re-encoding, as ImageMagick must do, since it
doesn't itself know about the PDF file format but relies on a
delegate.
I don't see any way to completely eliminate this and still have a JPEG
final output.
The PNG you posted doesn't show edge artifacts that I can see. It has
markedly different colors but that is because it started from the CMYK
pdf. Are the colors right if you start from the RGB pdf? If they are
not, then the solution would be to have Ghostscript (the PDF delegate)
use the right ICC profile that matches what is in the PDF.
Post by Avi Kouzi
I already tried the first one, it gives out pretty much the same results
as converted.jpg, the second one wouldn't run since I don't have those
ICM/ICC files (nowhere to be found on my filesystem).
Also, now that I have the RGB PDF, it is still not helping much (as
there is still a slight color diffrence and the edges issue).
Post by d***@imagemagick.org
Post by Avi Kouzi
It seems that the PDF was in CMYK
Did you try
convert -colorspace rgb image.pdf image.jpg
or
convert image.pdf -profile USWebCoatedSWOP.icc -profile sRGB.icm
image.jpg
Post by d***@imagemagick.org
Both methods are the suitable for properly converting a CMYK PDF to RGB
JPEG.
_______________________________________________
Magick-users mailing list
http://studio.imagemagick.org/mailman/listinfo/magick-users
Loading...