0
votes

I'm trying to convert a SVG file with a xlink:href for an image inside with ImageMagick using the command :

convert file.png result.png

But this gives me a blank png file, I'm sure that the problem comes from the image because others instructions are displayed in the png file. I can get it working by using the command :

convert msvg:file.svg result.png

Does someone knows how to make this work without the "msvg:" part? Because I have to do this with php-Imagick after and I can't add the "msvg:" in my php code.

SVG file :

<?xml version="1.0"?>
<svg id="svg" width="1024" height="1024" preserveAspectRatio="xMinYMin">
    <image id="svg-image" x="0" y="0" width="1024" height="1024" product_id="4" xlink:href="coeur.png">
    </image>
    <rect x="10" y="10" width="80" height="80" fill="red"/>
</svg>

ImageMagick version : 6.7.7.10-5+deb7u3

Output of "convert -list format | grep SVG" :

MSVG  SVG       rw+   ImageMagick's own SVG internal renderer
SVG  SVG       rw+   Scalable Vector Graphics (RSVG 2.36.1)
SVGZ  SVG       rw+   Compressed Scalable Vector Graphics (RSVG 2.36.1)

Php code :

$im = new Imagick();
$draw = new ImagickDraw();
$im->readImageBlob($svgParse->asXML());
$im->setImagePage(0, 0, 0, 0);
$im->scaleImage($viewBox['2'],$viewBox['3'], false);
foreach($ListText as $text){
   $draw->setFont(Mage::getBaseDir('media').DS.'font'.DS.$text['font-family'].".ttf");
   $draw->setFontSize( $text['font-size'] );
   $draw->setFillColor ( $text['fill']);
   $im->annotateImage($draw, $text['x'], $text['y'], 0, $text['text']);
}
/*png settings*/
$im->setImageFormat("png32");
// FB image
$imFB = clone $im;
$imFB->resizeImage(1200,630,Imagick::FILTER_LANCZOS,1);
$imFB->writeImage($filename_FB);
$imFB->clear();
$imFB->destroy();
// TW image
$imTW = clone $im;
$imTW->resizeImage(280,150,Imagick::FILTER_LANCZOS,1);
$imTW->writeImage($filename_TW);
$imTW->clear();
$imTW->destroy();

$im->writeImage($filename);/*(or .jpg)*/

$im->clear();
$im->destroy();
1
If you are using imagick, can you also post your current PHP code? - erjiang
I added my Php code to my post beacause it was too long for comments - JigokuArch
For security, rsvg delegate is not loading external image resources. Try setting the MSVG format before reading the blob date with $img->setFormat('MSVG'); - emcconville
Your answer solved my problem, thank you, you are my savior of the day :) - JigokuArch

1 Answers

1
votes

emcconvilutionle's answer was the solution, I just had to write

$im->setFormat('MSVG');

before

$im->readImageBlob($svgParse->asXML());