Page 1 of 1

Converting layered AI File to PNG

Posted: 2018-10-15T14:22:33-07:00
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();

Re: Converting layered AI File to PNG

Posted: 2018-10-15T19:27:36-07:00
by fmw42
Please always provide your Imagemagick version and Platform/OS. Also provide your input AI file so we can check out the issue.

Re: Converting layered AI File to PNG

Posted: 2018-10-16T01:26:40-07:00
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

Re: Converting layered AI File to PNG

Posted: 2018-10-16T09:26:24-07:00
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.

Re: Converting layered AI File to PNG

Posted: 2018-10-16T13:31:22-07:00
by Lagily
Yes, the command line one works, but the PHP one does not, that is the problem... any idea why?

Re: Converting layered AI File to PNG

Posted: 2018-10-16T13:36:23-07:00
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.