table

command
v0.0.0-...-80d7cf0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2021 License: BSD-3-Clause Imports: 9 Imported by: 0

README

Images example

This is a small example demonstrating the use of gd. The output in this README is derived from running example.go with gd example.go >README.md.

This comment will be rendered into the Markdown as plain text, Markdown rendering of a C-style comment requires the {md} tag immediately following the /* comment opening.


package main

import (
	"bytes"
	"fmt"
	"image"
	"log"
	"net/http"
	"path"

The "show" package is a magic package that is resolved by the gd build tool. The full path may also be used, then it would be "github.com/kortschak/gd/show".

	"show"

	_ "image/jpeg"
	_ "image/png"
)

var locations = []string{
	"https://blog.golang.org/gopher/glenda.png",
	"https://blog.golang.org/gopher/gopher.png",
	"https://blog.golang.org/gopher/header.jpg",
}

func main() {
	var buf bytes.Buffer
	fmt.Fprintln(&buf, "|URL|Format|File|")
	fmt.Fprintln(&buf, "|---|------|----|")
	for _, url := range locations {
		resp, err := http.Get(url)
		if err != nil {
			log.Fatal(err)
		}
		_, format, err := image.Decode(resp.Body)
		if err != nil {
			log.Fatal(err)
		}
		err = resp.Body.Close()
		if err != nil {
			log.Fatal(err)
		}
		fmt.Fprintf(&buf, "|%s|%s|%s|\n", url, format, path.Base(url))
	}
	show.Markdown(buf.String())
URL Format File
https://blog.golang.org/gopher/glenda.png png glenda.png
https://blog.golang.org/gopher/gopher.png png gopher.png
https://blog.golang.org/gopher/header.jpg jpeg header.jpg
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL