Last active
January 28, 2023 04:40
-
-
Save pokutuna/47d251e39e3bcf1de1074aa0307ede43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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