5

on server side I have an generated SVG XML source code. This should be changed to an image in order to offer a PNG (or JPG) download from an SVG XML code. Searching the web for a long time, I only found this solution using ImageMagick. Convert SVG image to PNG with PHP But I don't have access to the ImageMagick library so I need a different way to convert SVG XML Code to a bitmap image.

Does anybody have an idea?

Brw: It's not an option to save that svg an execute an binary or script on operating system to convert.

Thank you.

4

1 回答 1

0

您需要使用蜡染库。下载它,放在你项目的某个地方。然后在 php 中使用 shell_exec() 函数调用 batik 命令。它将需要几秒钟并将您的 svg 转换为 png。

例子:-

outputfile ='path where you want to lace png'
$tempSVG_filename = '/var/www' . $baseUrl . '/png/temp.svg';
$tempSVG_handle = fopen($tempSVG_filename, 'w+');
fwrite($tempSVG_handle, $YourSVG);
fclose($tempSVG_handle);
$mimetype = 'image/png';
$width = '6000';

$result = shell_exec('java  -jar /var/www/svgtopng/batik-1.7/batik-rasterizer.jar -m ' . $mimetype . ' -d ' . $outputfile . ' -w ' . $width . ' ' . $tempSVG_filename . ' 2>&1');
 unlink($tempSVG_filename);
于 2013-07-13T23:09:21.643 回答