Convert SVG image to PNG with PHP

后端 未结 8 2201
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 14:46

I\'m working on a web project that involves a dynamically generated map of the US coloring different states based on a set of data.

This SVG file gives me a good b

8条回答
  •  盖世英雄少女心
    2020-11-22 15:36

    This is v. easy, have been doing work on this for the past few weeks.

    You need the Batik SVG Toolkit. Download, and place the files in the same directory as the SVG you want to convert to a JPEG, also make sure you unzip it first.

    Open the terminal, and run this command:

    java -jar batik-rasterizer.jar -m image/jpeg -q 0.8 NAME_OF_SVG_FILE.svg
    

    That should output a JPEG of the SVG file. Really easy. You can even just place it in a loop and convert loads of SVGs,

    import os
    
    svgs = ('test1.svg', 'test2.svg', 'etc.svg') 
    for svg in svgs:
        os.system('java -jar batik-rasterizer.jar -m image/jpeg -q 0.8 '+str(svg)+'.svg')
    

提交回复
热议问题