duan5801 2017-03-24 07:06
浏览 2277
已采纳

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

I have following code snippet for e.g.

package main

import (
    "github.com/ajstarks/svgo"
    "os"
    _ "image"
    _ "fmt"
)

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

    canvas := svg.New(os.Stdout)
    canvas.Start(width,height)
    canvas.Image(0,0,512,512,"src.jpg","0.50")
    canvas.End()
}

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 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)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮