0

I'm trying to convert an inline SVG to JPG using ImageMagick. I get a JPG back from the server but the remote image defined in the xlink is always blank. I tested with a SVG with some basic vector shapes and I do see those in the resulting JPEG but this example referencing an external image does not work.

<?php
$mySVG = '<?xml version="1.0" encoding="utf-8"?><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 500 700" style="enable-background:new 0 0 500 700;" xml:space="preserve" width="500"><image style="overflow:visible;" width="500" height="700" xlink:href="http://www.sportsupplygroup.com/SVG_POC/lifter.jpg" transform="matrix(0.948 0 0 0.948 11 36.4)"></image></svg>';


$svg = $mySVG;
$jpeg = new Imagick();
$jpeg->readImageBlob($svg);
$jpeg->setImageFormat("JPEG");
header("Content-Type: image/jpeg");
echo $jpeg;
?>

Being able to load different images into layers of the SVG gives us the ability to deliver some dynamic content. We want to use this in a HTML email but since SVG is not really supported, I want to convert to something that is like a JPG. Email would call a script like this. <img src="createImage.php"> <!-- call php to get the image -->

Where the script could create the SVG with it's layers and send back a JPG. Is there a better way to convert SVG to JPG/PNG server side?

Ashley
  • 1
  • 3
  • you could try converting the image to a data uri first so it's not remote – Robert Longson Aug 01 '17 at 20:10
  • Most modern SVG libraries have disabled image:xlink feature due to security issues. – emcconville Aug 01 '17 at 20:14
  • Being able to load different images into layers of the SVG gives us the ability to deliver some dynamic content. We want to use this in a HTML email but since SVG is not really supported, I want to convert to something that is like a JPG. Email would call a script like this. Where the script could create the SVG with it's layers and send back a JPG. Better way to do? – Ashley Aug 01 '17 at 20:46
  • **but since SVG is not really supported** : https://stackoverflow.com/questions/8926285/svg-browser-support So the real question is to know if IM supports more SVG features than the browsers (and if your SVG are likely to uses the less-supported features). – xenoid Aug 02 '17 at 08:34
  • I said SVG is not supported in **email**. The SVG features were using like image element are supported in browsers. I don't understand why IM doesn't load the image when doing the conversion. emcconville says security issue. – Ashley Aug 02 '17 at 13:45

0 Answers0