.AI CMYK transparency error

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
ayrton.ricardo
Posts: 6
Joined: 2017-10-05T04:55:01-07:00
Authentication code: 1151

.AI CMYK transparency error

Post by ayrton.ricardo »

Hi guys,

I'm trying to do:
  • Convert a .AI file in a .PNG file;
  • Merge a .AI file with a PNG file;
In both cases the transparency isn't available, but when I use the convert command the error doesn't appear.

PHP CODE:

Code: Select all

$file1 = 'a.ai';
$out = 'c.png';

// read page 1
$im = new \Imagick();
$im->readImage($file1);
$im->setImageBackgroundColor(new \ImagickPixel('transparent'));
$im->setBackgroundColor(new \ImagickPixel('transparent'));
$im->setColorspace(\Imagick::COLORSPACE_SRGB);
$im->transformImageColorspace(\Imagick::COLORSPACE_SRGB);
$im->writeImages($out, true);
$im->clear();
$im->destroy();
Source: a.ai
Result: c.png

Command:

Code: Select all

convert -density 300 -colorspace srgb a.ai c2.png
Source: a.ai
Result: c2.png

This error only appears when the profile of colors is CMYK, when I use RGB the error doesn't appear.

Anyone know how to fix it?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: .AI CMYK transparency error

Post by snibgo »

In PHP, try "setImageColorspace". See http://php.net/manual/en/imagick.setimagecolorspace.php
snibgo's IM pages: im.snibgo.com
ayrton.ricardo
Posts: 6
Joined: 2017-10-05T04:55:01-07:00
Authentication code: 1151

Re: .AI CMYK transparency error

Post by ayrton.ricardo »

I used this option before, I tried again and the result:

CODE:

Code: Select all

// read page 1
$im = new \Imagick();
$im->readImage($file1);
$im->setImageBackgroundColor(new \ImagickPixel('transparent'));
$im->setBackgroundColor(new \ImagickPixel('transparent'));
$im->setColorspace(\Imagick::COLORSPACE_SRGB);
$im->setImageColorspace(\Imagick::COLORSPACE_SRGB); // ALTERATION
$im->transformImageColorspace(\Imagick::COLORSPACE_SRGB);
$im->writeImages($out, true);
$im->clear();
$im->destroy();

Result: c.png

I used the function `$im->negateImage(false, Imagick::CHANNEL_ALL);` but still without transparency background.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: .AI CMYK transparency error

Post by fmw42 »

Your posted images have been converted from .ai to .pdf. Please post to some place that does not change the image format or zip the files first.

Try setting the colorspace first and the background color before reading in the input AI

Code: Select all

// read page 1
$im = new \Imagick();
$im->setColorspace(\Imagick::COLORSPACE_SRGB);
$im->setBackgroundColor(new \ImagickPixel('transparent'));
$im->readImage($file1);
$im->writeImages($out, true);
$im->clear();
$im->destroy();
But I think you also need to specify the format for the output file.
ayrton.ricardo
Posts: 6
Joined: 2017-10-05T04:55:01-07:00
Authentication code: 1151

Re: .AI CMYK transparency error

Post by ayrton.ricardo »

I don't know how exactly that format works, but here has another .ai example: https://1drv.ms/u/s!AmISJy6AbeQ7hPIziQPfQ2dyL2XYeg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: .AI CMYK transparency error

Post by fmw42 »

ayrton.ricardo wrote: 2017-10-05T10:18:34-07:00 I don't know how exactly that format works, but here has another .ai example: https://1drv.ms/u/s!AmISJy6AbeQ7hPIziQPfQ2dyL2XYeg
That also has been changed to PDF. You must find another image hosting service or zip the AI file first before uploading.
ayrton.ricardo
Posts: 6
Joined: 2017-10-05T04:55:01-07:00
Authentication code: 1151

Re: .AI CMYK transparency error

Post by ayrton.ricardo »

I saved a file by Adobe Illustrator and zipped it: https://www.dropbox.com/s/qrzx51g8tfrn5 ... i.zip?dl=0
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: .AI CMYK transparency error

Post by fmw42 »

This command line works fine for me.

Code: Select all

convert -colorspace sRGB -background none logo-teste.ai test.png
You just need to find the equivalent Imagick commands and do them in the same order as in my command.
ayrton.ricardo
Posts: 6
Joined: 2017-10-05T04:55:01-07:00
Authentication code: 1151

Re: .AI CMYK transparency error

Post by ayrton.ricardo »

fmw42 wrote: 2017-10-05T15:07:50-07:00 This command line works fine for me.

Code: Select all

convert -colorspace sRGB -background none logo-teste.ai test.png
You just need to find the equivalent Imagick commands and do them in the same order as in my command.
The command work's fine as expected, the problem is the PHP code.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: .AI CMYK transparency error

Post by fmw42 »

Sorry I do not know Imagick that well.
ayrton.ricardo
Posts: 6
Joined: 2017-10-05T04:55:01-07:00
Authentication code: 1151

Re: .AI CMYK transparency error

Post by ayrton.ricardo »

Hi,

After update Ghostscript the problem was solved to ".ai" file, but eps still with problem if I use shadow on file.

Code: Select all

convert -background none -density 300 -colorspace sRGB teste-sombra-rgb.ai 2.png
The files:
teste-sombra-rgb.ai
teste-sombra-cmyk.ai

teste-sombra-cmyk copiar.eps
teste-sombra-rgb.eps
Post Reply