PDF image colorspace [RESOLVED]
PDF image colorspace [RESOLVED]
Hi
I'm using imagick to generate pdf's from a series of elements/tiles. Everything works fine except for the colors.
If I set the image format to png and then use the convert cli the colors are correct (ie intermediary of png).
If I go straight to pdf (ie set image format as pdf) the colors are washed out. I've tried several different values of setImageColorSpace as follows (RGB, sRGB, CMYK) but it is not working.
Here is a sample of the color if I use png as intermediate format (and the color seen in html).
Here is a sample of the straight to pdf color
Any clues?
I'm using imagick to generate pdf's from a series of elements/tiles. Everything works fine except for the colors.
If I set the image format to png and then use the convert cli the colors are correct (ie intermediary of png).
If I go straight to pdf (ie set image format as pdf) the colors are washed out. I've tried several different values of setImageColorSpace as follows (RGB, sRGB, CMYK) but it is not working.
Here is a sample of the color if I use png as intermediate format (and the color seen in html).
Here is a sample of the straight to pdf color
Any clues?
Last edited by larowlan on 2010-03-17T21:08:23-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: PDF image colorspace
did you see viewtopic.php?f=18&t=15708 just two topics down the list? apparently it is not yet implemented in Imagick, but they are working on it.
Re: PDF image colorspace
Cheers, no I didn't read this through to the end as it was more to do with jpeg and reading pdfs rather than creating pdfs. If the function is not implemented, why doesn't it give an error?
Why does making a png work but making a pdf not work - is this because image magick uses a different colorspace for pdf by default?
Why does making a png work but making a pdf not work - is this because image magick uses a different colorspace for pdf by default?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: PDF image colorspace
I cannot answer that. Perhaps I misunderstand your issue vs viewtopic.php?f=18&t=15708.
But perhaps it has to do with your ghostscript? I am not sure whether ghostscript is needed to convert from or to pdf.
What version of IM are you using and what version of ghostscript.
Have you tried just using command line?
When I do:
convert -size 100x100 xc:blue blue.png
convert -size 100x100 xc:blue blue.pdf
I get exactly the same color when I look at the results.
But perhaps it has to do with your ghostscript? I am not sure whether ghostscript is needed to convert from or to pdf.
What version of IM are you using and what version of ghostscript.
Have you tried just using command line?
When I do:
convert -size 100x100 xc:blue blue.png
convert -size 100x100 xc:blue blue.pdf
I get exactly the same color when I look at the results.
Re: PDF image colorspace
Yeah, I too get the same colour with the cli, but unfortunately this is part of a larger php/web app which needs to generate the pdf on the fly. If I can't get it to work, I'll need to look at caching the png as a file and using convert via the php exec or equivalent function - not that I'm keen on it!.
My versions are:
ghostscript-8.63-1.fc8
ImageMagick-6.3.5.10-1.fc8
My versions are:
ghostscript-8.63-1.fc8
ImageMagick-6.3.5.10-1.fc8
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: PDF image colorspace
larowlan wrote:Yeah, I too get the same colour with the cli, but unfortunately this is part of a larger php/web app which needs to generate the pdf on the fly. If I can't get it to work, I'll need to look at caching the png as a file and using convert via the php exec or equivalent function - not that I'm keen on it!.
My versions are:
ghostscript-8.63-1.fc8
ImageMagick-6.3.5.10-1.fc8
That is a rather old version of IM. I know that ISPs are reluctant to upgrade, but if you have the option then perhaps you should.
What API are you using for your PHP? Imagick? Perhaps there is an issue there. What are your commands to generate the PDF?
Re: PDF image colorspace
If I save the pdf generated then convert it to a png using convert, the colours are correct again!
I think it is some sort of CMYK to RGB type issue between pdf format and other image formats.
I think it is some sort of CMYK to RGB type issue between pdf format and other image formats.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: PDF image colorspace
Perhaps I am missing something, but the swatch you posted as a pdf is really jpg? and so it the png?
Again, can you post your commands as I am unsure what you are doing in the way of creating the swatches, especially the pdf and if you then need to convert to other image types.
If converting a cmyk pdf to some other format, one needs to set the colorspace before reading the image. This was the issue that I thought was not coded in Imagick in the other post I mentioned.
However, if you are creating a pdf and not doing anything to it, then it should work as from the command line, unless there is some issue either with your IM version or the version of IMagick.
Again, can you post your commands as I am unsure what you are doing in the way of creating the swatches, especially the pdf and if you then need to convert to other image types.
If converting a cmyk pdf to some other format, one needs to set the colorspace before reading the image. This was the issue that I thought was not coded in Imagick in the other post I mentioned.
However, if you are creating a pdf and not doing anything to it, then it should work as from the command line, unless there is some issue either with your IM version or the version of IMagick.
Re: PDF image colorspace
I can upgrade (no isp) but I'd need to upgrade the whole OS to the newest Fedora and I don't have the time for that unfortunately, maybe later in the month.
I am using imagick, the commands are quite involved as it is taking an array of tiles/images and converting them (the whole thing is inside a Drupal module as well).
Here are the relevant bits
If I change the two refs to pdf to png (eg the header and the setImageFormat) I get the correct green, with pdf, the colour is washed. -
here is the png version
This is an edited bit of my code but demonstrates the basics for this issue and should run on your machine (can't see any dependencies on my code!)
I am using imagick, the commands are quite involved as it is taking an array of tiles/images and converting them (the whole thing is inside a Drupal module as well).
Here are the relevant bits
Code: Select all
$image = new Imagick();
$image->setResolution(300, 300);
$image->newImage(1181, 1181,
new ImagickPixel('none')); //new image w/ transparency
//make it a pdf
$image->setImageFormat('pdf');
$image->setImageColorspace(imagick::COLORSPACE_RGB);
$image->setCompression(imagick::COMPRESSION_ZIP);
$image->setCompressionQuality(80);
//adding the rectangle
$background = new ImagickPixel('#00ff00'); //green for example
$tile_img = new Imagick();
$tile_img->newImage(500,
500,
$background);
//combine the tile into the image (this is done lots of times)
$image->compositeImage($tile_img,
Imagick::COMPOSITE_DEFAULT,
10,
10);
//output the image
header("Content-type: application/pdf");
echo $image->getImageBlob();
here is the png version
Code: Select all
$image = new Imagick();
$image->setResolution(300, 300);
$image->newImage(1181, 1181,
new ImagickPixel('none')); //new image w/ transparency
//make it a pdf
$image->setImageFormat('png');
$image->setImageColorspace(imagick::COLORSPACE_RGB);
$image->setCompression(imagick::COMPRESSION_ZIP);
$image->setCompressionQuality(80);
//adding the rectangle
$background = new ImagickPixel('#00ff00'); //green for example
$tile_img = new Imagick();
$tile_img->newImage(500,
500,
$background);
//combine the tile into the image (this is done lots of times)
$image->compositeImage($tile_img,
Imagick::COMPOSITE_DEFAULT,
10,
10);
//output the image
header("Content-type: image/png");
echo $image->getImageBlob();
Re: PDF image colorspace
here are the output files
- Attachments
-
- 31.zip
- the pdf (had to make it a zip)
- (900 Bytes) Downloaded 1078 times
-
- the png
- 31.png (194 Bytes) Viewed 29718 times
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: PDF image colorspace
this looks on the surface like the problem mentioned in the other topic where it was suggested to move the setting of the colorspace right after the creation of the image
$image = new Imagick();
$image->setImageColorspace(imagick::COLORSPACE_RGB);
...
Don't know if that will help as Imagick may not be able to do that yet as I read that other topic. But that is what may be needed in command line, if I understand your problem.
$image = new Imagick();
$image->setImageColorspace(imagick::COLORSPACE_RGB);
...
Don't know if that will help as Imagick may not be able to do that yet as I read that other topic. But that is what may be needed in command line, if I understand your problem.
Re: PDF image colorspace
Also, for what it is worth - the following lines don't make an impact (I've taken them out/added them in)
But changing the first line to
Makes a huge difference - the colours become black/brown etc (so I think that setImageColorSpace might be implemented!)
Code: Select all
$image->setImageColorspace(imagick::COLORSPACE_RGB);
$image->setCompression(imagick::COMPRESSION_ZIP);
$image->setCompressionQuality(80);
Code: Select all
$image->setImageColorspace(imagick::COLORSPACE_CMYK);
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: PDF image colorspace
your pdf and png look to me to have the same green color when opened in Mac Preview.
Re: PDF image colorspace
Adding the setImageColorSpace straight after the new $imagick throws an error
'Can not process empty Imagick object'
If I move it down, 1 line at a time, as soon as I pass this line
The error is no longer thrown but the poor colour remains!
Is it to do with my background maybe?
'Can not process empty Imagick object'
If I move it down, 1 line at a time, as soon as I pass this line
Code: Select all
$image->newImage(50, 50,
new ImagickPixel('none')); //new image w/ transparency
Is it to do with my background maybe?