CYMK PDF, AI or EPS to PNG
-
- Posts: 4
- Joined: 2016-06-27T02:51:56-07:00
- Authentication code: 1151
CYMK PDF, AI or EPS to PNG
When a user uploads a CMYK vector file either as a PDF, AI or EPS. I want to extract a small PNG without a white background or colour loss for use in a browser. However this could actually be a bug I have posted all the information to describe this problem here: http://stackoverflow.com/questions/3769 ... background We are willing to pay for a functional code snippet, as we are not sure if this is actually a bug or not. Just a note, linear PDF's in CYMK seem to work ok.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: CYMK PDF, AI or EPS to PNG
PNG does not support CMYK, so you need to convert to sRGB. This works for me
Code: Select all
convert -background none -colorspace sRGB test_cmyk.pdf test_cmyk.png
-
- Posts: 4
- Joined: 2016-06-27T02:51:56-07:00
- Authentication code: 1151
Re: CYMK PDF, AI or EPS to PNG
This is what we are doing, but it's unfortunately not working with the conversion. I Have been told this a possible bug? We can't force our users to covert CYMK to sRGB before they upload their files. Here is the snippet of code I'm using to convert to sRBG:
Code: Select all
$f = $_FILES['imageLoader']['name'];
$im = new Imagick();
$im->setBackgroundColor(new ImagickPixel('transparent'));
$im->readImage("upload/$t/$f");
$width = $im->getImageWidth();
if (pathinfo($f, PATHINFO_EXTENSION) == 'psd') {
$im = $im->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
}
if (pathinfo($f, PATHINFO_EXTENSION) == 'svg') {
$im->setBackgroundColor(new ImagickPixel('transparent'));
$svg = file_get_contents("upload/$t/$f");
$im->readImageBlob($svg);
}
if (pathinfo($f, PATHINFO_EXTENSION) == 'ai') {
$im->transformImageColorspace(Imagick::COLORSPACE_SRGB);
}
if (pathinfo($f, PATHINFO_EXTENSION) == 'pdf') {
$im->transformImageColorspace(Imagick::COLORSPACE_SRGB);
}
$im->thumbnailImage(149, 240, true);
$im->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
$im->setImageResolution(72,72);
$im->resampleImage(72,72,imagick::FILTER_UNDEFINED,0);
$im->setImageFormat('png32');
$im->writeImage($outFile);
// clean up
$im->clear();
$im->destroy();
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: CYMK PDF, AI or EPS to PNG
Under IM v6.9.2-5, GS 9.15:
x2.tiff has no transparency, although Adobe Reader shows the background is transparent.
"-verbose" shows IM is using "-sDEVICE=pamcmyk32". I don;t know if that is significant.
Working from test_cmyk_web_enabled.pdf, the conversion does have a transparent background. I notice that IM uses "-sDEVICE=pngalpha".
Code: Select all
convert -verbose test_cmyk.pdf x2.tiff
"-verbose" shows IM is using "-sDEVICE=pamcmyk32". I don;t know if that is significant.
Working from test_cmyk_web_enabled.pdf, the conversion does have a transparent background. I notice that IM uses "-sDEVICE=pngalpha".
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: CYMK PDF, AI or EPS to PNG
I am not suggesting that, but you can convert it for them.We can't force our users to covert CYMK to sRGB before they upload their files
If you need cmyk with transparency, then you cannot output to png, but you can output to tif. So this works for me
Code: Select all
convert -background none -colorspace sRGB test_cmyk.pdf -profile /Users/fred/Images/profiles/USWebCoatedSWOP.icc test_cmyk.tif
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: CYMK PDF, AI or EPS to PNG
Yes, I think this is significant. You need an sDEVICE that permits transparency. I suspect that pamcmyk32 is not alpha compatible. But I am no expert on this. PNG works for RGB since it use sDEVICE=pngalpha, which permits transparency to be retained. One would need to look at the NetPBM pamcmyk32 docs to see if it is alpha compatible and if not, find an alpha compatible alternative for cmyka."-verbose" shows IM is using "-sDEVICE=pamcmyk32". I don;t know if that is significant.
Working from test_cmyk_web_enabled.pdf, the conversion does have a transparent background. I notice that IM uses "-sDEVICE=pngalpha".
-
- Posts: 4
- Joined: 2016-06-27T02:51:56-07:00
- Authentication code: 1151
Re: CYMK PDF, AI or EPS to PNG
I think you've maybe misunderstood the question? I do not need CMYK with transparency, I need a PNG (thumbnail) with transparency from a user uploaded CYMK PDF, EPS or AI file. This thumbnail will be displayed in a web browser. Of course the PNG will be in RGB. Tiff's are unfortunately not widely supported in most browsers.If you need cmyk with transparency, then you cannot output to png, but you can output to tif. So this works for me
Re: CYMK PDF, AI or EPS to PNG
Try this command:
- convert -colorspace sRGB test_cmyk.pdf test_cmyk.png
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: CYMK PDF, AI or EPS to PNG
That is exactly what I gave you in my first post above. Since PNG does not support cmyk, you must convert to sRGB. This command worked for me and gives transparency.I think you've maybe misunderstood the question? I do not need CMYK with transparency, I need a PNG (thumbnail) with transparency from a user uploaded CYMK PDF, EPS or AI file. This thumbnail will be displayed in a web browser. Of course the PNG will be in RGB. Tiff's are unfortunately not widely supported in most browsers.
Code: Select all
convert -background none -colorspace sRGB test_cmyk.pdf result.png
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: CYMK PDF, AI or EPS to PNG
Your code is different to Fred's command. Fred's command has "-colorspace sRGB" before reading the PDF. Your code converts to sRGB after reading the PDF.bobby solo wrote:Here is the snippet of code I'm using to convert to sRBG:
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: CYMK PDF, AI or EPS to PNG
With vector format input images, you must provide a few settings before reading the images. For cmyk vector images, you must tell it to convert to srgb before reading the input. I am not sure about the -background none. Sometimes that is needed. It does not hurt to add it if you do want a transparent background. You might also need to provide the desired density before reading the vector input. That will control the output PNG size. If you have line drawings or such, then using a larger density before reading the input and resizing afterwards to compensate (supersampling technique), will give better resolution. I generally do not use -resample, but prefer to use -density (before reading the input), -resize and then -density again after reading the input to set the output pixel dimensions and the desired print density/resolution.
-
- Posts: 4
- Joined: 2016-06-27T02:51:56-07:00
- Authentication code: 1151
Re: CYMK PDF, AI or EPS to PNG
Thanks a lot to both of you, especially for the last comment explaining about vector images. I got the code working now, colorspace had to be set before reading the files. I've updated the original post in Stackoverflow.