0

After read the answers for: Convert SVG image to PNG with PHP Convert SVG to PNG image Convert a bunch of images from svg to png I finally get a working code, at my lab it works fine but when I upload that to my server, the script fails.

The function I use is the following:

function svg2png($svg, $nomarchpng, $parametros = null) {
    $im = new Imagick();
    $im->readImageBlob($svg);
    $im->setImageFormat("png32");
    if (isset($parametros->ancho) && isset($parametros->alto))
        $im->resizeImage( $parametros->ancho
                        , $parametros->alto
                        , imagick::FILTER_LANCZOS
                        , 1);
    $im->writeImage($nomarchpng);
    $im->clear();
    $im->destroy();
}

At my lab, a linux Mageia machine with php 5.6.33 and imagick module version 3.4.1 imagick classes Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel Imagick compiled with ImageMagick version ImageMagick 6.9.8-7 Q16 x86_64 2017-05-27

On that environment the resulting png looks pretty good.

But when I upload that script to my server the resulting png is a blank png with the right dimentions and white background.

The server is a FreeBSD with PHP Version 5.6.33 imagick module version 3.4.3 imagick classes Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel Imagick compiled with ImageMagick version ImageMagick 6.9.9-28 Q16 amd64 2018-02-23

I tought that maybe the problem was related with charsets, then I force php with ini_set('default_charset', 'utf8'); but png still blanck.

Could you tell me a clue... maybe how to debug the png generation in order to see what is happening step by step.

Thanks in advance.

gramo
  • 103
  • 6
  • try do a phpinfo(); and confirm Imagick is set up? Also that the extensions is not empty under the Imagick header – Marinus Mar 08 '18 at 03:59
  • Check the type and versions of the delegate being used to render your SVG files on each server and the versions of libpng. You should be able to see that using `convert -list format` and look for the lines for SVG and PNG. With regard to SVG, it could be MSVG/XML (IM internal renderer), RSVG or Inkscape in order of quality of rendering. But it may just be an different version of these libraries that is causing the issue. – fmw42 Mar 08 '18 at 07:52
  • The data about php version and Imagick version and classes was taked from the phpinfo() output in both servers. – gramo Mar 08 '18 at 13:07
  • At lab Linux Mageia I get (on gd módule) the following information: PNG Support enabled libPNG Version 1.6.34 ImageMagick supported formats: PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, SVG, SVGZ... and others – gramo Mar 08 '18 at 13:09
  • At FreeBSD server I get (on the same gd): PNG Support enabled libPNG Version 1.6.34 ImageMagick supported formats PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, SVG, SVGZ, – gramo Mar 08 '18 at 13:10
  • I use inkscape to generate the template, and I embed some tags like NAMEOFPERSON in order to change that with a php preg_replace('/NAMEOFPERSON', $databasename, $svg); At lab there is no issue, and png is pretty good generated. – gramo Mar 08 '18 at 13:13

0 Answers0