Skip to content

Instantly share code, notes, and snippets.

@pokutuna
Last active January 28, 2023 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pokutuna/47d251e39e3bcf1de1074aa0307ede43 to your computer and use it in GitHub Desktop.
Save pokutuna/47d251e39e3bcf1de1074aa0307ede43 to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"image"
"log"
"os"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
"github.com/fogleman/gg"
)
var (
path = flag.String("image", "", "image file path to draw lines")
w = flag.Int("w", 0, "count of width in pieces")
h = flag.Int("h", 0, "count of height in pieces")
)
func main() {
flag.Parse()
if *path == "" {
log.Fatal("Must give -image")
}
file, err := os.Open(*path)
if err != nil {
log.Fatal(err)
}
img, _, err := image.Decode(file)
if err != nil {
log.Fatal(err)
}
b := img.Bounds()
dc := gg.NewContextForImage(img)
dc.SetHexColor("FFFF00")
if 1 < *w {
pw := float64(b.Dx()) / float64(*w)
for i := 1; i < *w; i++ {
x := float64(i) * pw
dc.DrawLine(x, float64(b.Min.Y), x, float64(b.Max.Y))
dc.Stroke()
}
}
if 1 < *h {
ph := float64(b.Dy()) / float64(*h)
for i := 1; i < *h; i++ {
y := float64(i) * ph
dc.DrawLine(float64(b.Min.X), y, float64(b.Max.X), y)
dc.Stroke()
}
}
dc.SavePNG("out.png")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment