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

如何在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)

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?