2017-03-24 07:06 阅读 392

如何在Golang中将svg创建和导出到png / jpeg

I have following code snippet for e.g.

package main

import (
    _ "image"
    _ "fmt"

func main(){
    width := 512
    height := 512

    canvas := svg.New(os.Stdout)

I want to export svg created by this code to jpeg or png or svg let's say. How to do that I am not getting idea. I can use imagemagick or something but for that I need SVG thing. please someone help me with this.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    douzhao4071 douzhao4071 2017-03-24 12:47

    To output an .svg file just pass a file Writer to svg.New

    f, err := os.Create("my_new_svg.svg")
    ... handle error
    canvas := svg.New(f)

    This will save your output in my_new_svg.svg. Once you have done this you can open in your favorite web browser etc. I'd guess the easiest way to get a .png or .jpeg is to use some external tool (like Image Magick)

    点赞 评论 复制链接分享