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.
ayrton.ricardo
Posts: 6 Joined: 2017-10-05T04:55:01-07:00
Authentication code: 1151
Post
by ayrton.ricardo » 2017-10-05T05:00:39-07:00
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
Post
by snibgo » 2017-10-05T05:11:29-07:00
ayrton.ricardo
Posts: 6 Joined: 2017-10-05T04:55:01-07:00
Authentication code: 1151
Post
by ayrton.ricardo » 2017-10-05T06:56:24-07:00
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.
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Post
by fmw42 » 2017-10-05T10:13:07-07:00
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.
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Post
by fmw42 » 2017-10-05T10:24:15-07:00
That also has been changed to PDF. You must find another image hosting service or zip the AI file first before uploading.
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Post
by fmw42 » 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.
ayrton.ricardo
Posts: 6 Joined: 2017-10-05T04:55:01-07:00
Authentication code: 1151
Post
by ayrton.ricardo » 2017-10-06T10:51:04-07:00
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.
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Post
by fmw42 » 2017-10-06T11:05:03-07:00
Sorry I do not know Imagick that well.