// NewFormattedCanvas creates a new vg.CanvasWriterTo with the specified // image format. // // Supported formats are: // // eps, jpg|jpeg, pdf, png, svg, and tif|tiff. func NewFormattedCanvas(w, h vg.Length, format string) (vg.CanvasWriterTo, error) { var c vg.CanvasWriterTo switch format { case "eps": c = vgeps.New(w, h) case "jpg", "jpeg": c = vgimg.JpegCanvas{Canvas: vgimg.New(w, h)} case "pdf": c = vgpdf.New(w, h) case "png": c = vgimg.PngCanvas{Canvas: vgimg.New(w, h)} case "svg": c = vgsvg.New(w, h) case "tif", "tiff": c = vgimg.TiffCanvas{Canvas: vgimg.New(w, h)} default: return nil, fmt.Errorf("unsupported format: %q", format) } return c, nil }
// WriterTo returns an io.WriterTo that will write the plot as // the specified image format. // // Supported formats are: // // eps, jpg|jpeg, pdf, png, svg, and tif|tiff. func (p *Plot) WriterTo(w, h vg.Length, format string) (io.WriterTo, error) { var c interface { vg.CanvasSizer io.WriterTo } switch format { case "eps": c = vgeps.New(w, h) case "jpg", "jpeg": c = vgimg.JpegCanvas{Canvas: vgimg.New(w, h)} case "pdf": c = vgpdf.New(w, h) case "png": c = vgimg.PngCanvas{Canvas: vgimg.New(w, h)} case "svg": c = vgsvg.New(w, h) case "tif", "tiff": c = vgimg.TiffCanvas{Canvas: vgimg.New(w, h)} default: return nil, fmt.Errorf("unsupported format: %q", format) } p.Draw(draw.New(c)) return c, nil }