SVG to JPG / PNG

谁都会走 提交于 2019-12-21 09:10:51

问题


Is there any working module to convert a SVG image into a pixel format like JPEG or PNG?


回答1:


Take a look at the Batik toolkit. Specifically the rasterizer:

http://xmlgraphics.apache.org/batik/tools/rasterizer.html




回答2:


If you're using PEAR you can the XML_svg2image package (http://pear.php.net/package/XML_svg2image/). If not you should take a look at ImageMagick command line tool (http://www.imagemagick.org/script/command-line-tools.php). The convert program is quite simple to use : http://www.imagemagick.org/script/convert.php#usage




回答3:


If you have imagemagick installed (the tool, not sure how it would work with the PHP package), it can be as simple as:

<?php
  `convert infile.svg outfile.jpg`
?>



回答4:


We can also use command line interface such as inkscape to achieve it. Download inkscape from inkscape.org

Open Terminal/command prompt Type command as:

single file conversion

inkscape -z --file=original.svg --export-png=converted.png --export-area-drawing --export-dpi=200

Batch conversion of SVG's to PNG can be achieved as follows :

for i in *.svg; 
   do inkscape -z --file=$i --export-png=$i.png --export-area-drawing --export-dpi=200; 
done

--export-area-drawing : This will only export the drawing area of SVG file and not the whole document area.



来源:https://stackoverflow.com/questions/2995640/svg-to-jpg-png

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!