Converting layered AI File to PNG

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Lagily
Posts: 3
Joined: 2018-10-15T14:19:39-07:00
Authentication code: 1152

Converting layered AI File to PNG

Post by Lagily »

Hello

I cannot seem to be able to convert a layered AI File properly into a PNG, at least one layer seems to be missing. I am able to convert it using command line properly and am wondering how I can achieve the same using the PHP library, can anyone here help me?

This works just fine:

Code: Select all

    $convertCmd = "magick convert " . APP_ROOT . "/user_content/logo_oetwil_ps.ai " . APP_ROOT . "/user_content/logo_oetwil_ps.ai.png";
    exec($convertCmd);
This does not contain all the layers in the PNG:

Code: Select all

    $im = new Imagick();
    $im->readImage(APP_ROOT . "/user_content/logo_oetwil_ps.ai");
    //$im->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN); // This does not seem to help either
    
    $im->setImageFormat("png");
    header("Content-Type: image/png");
    echo $im->getImageBlob();
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting layered AI File to PNG

Post by fmw42 »

Please always provide your Imagemagick version and Platform/OS. Also provide your input AI file so we can check out the issue.
Lagily
Posts: 3
Joined: 2018-10-15T14:19:39-07:00
Authentication code: 1152

Re: Converting layered AI File to PNG

Post by Lagily »

I'm on Windows 10, command line:

Code: Select all

Version: ImageMagick 7.0.8-12 Q16 x86 2018-09-23 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib cairo flif freetype gslib heic jng jp2 jpeg lcms lqr lzma openexr pangocairo png ps raw rsvg tiff webp xml zlib
PHP imagick module version: 3.4.3

AI file: https://ufile.io/j0pek
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting layered AI File to PNG

Post by fmw42 »

This works fine for me on Imagemagick 6.9.10.12 Q16 Mac OSX with Ghostscript 9.24.

Code: Select all

convert logo_oetwil_ps.ai ai.png
Check your version of Ghostscript and be sure it is current.

For IM 7, use magick rather than convert.
Lagily
Posts: 3
Joined: 2018-10-15T14:19:39-07:00
Authentication code: 1152

Re: Converting layered AI File to PNG

Post by Lagily »

Yes, the command line one works, but the PHP one does not, that is the problem... any idea why?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting layered AI File to PNG

Post by fmw42 »

It is likely due to an older version of Ghostscript. You can check your version with PHP exec() calling gs --version.

<?php
exec("gs --version",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>

If you find it old, then you should upgrade it. If you are on a hosted platform, then you will need to ask the hosting provider to do the upgrade.
Post Reply