Jelajahi Sumber

Extra flag -i to invert black and white (negative photo).

Deleplace 8 tahun lalu
induk
melakukan
561ea7ec75
1 mengubah file dengan 6 tambahan dan 1 penghapusan
  1. 6 1
      qrcode/main.go

+ 6 - 1
qrcode/main.go

@@ -17,6 +17,7 @@ func main() {
 	outFile := flag.String("o", "", "out PNG file prefix, empty for stdout")
 	size := flag.Int("s", 256, "image size (pixel)")
 	textArt := flag.Bool("t", false, "print as text-art on stdout")
+	negative := flag.Bool("i", false, "invert black and white")
 	flag.Usage = func() {
 		fmt.Fprintf(os.Stderr, `qrcode -- QR Code encoder in Go
 https://github.com/skip2/go-qrcode
@@ -56,11 +57,15 @@ Usage:
 	checkError(err)
 
 	if *textArt {
-		art := qr2String(q, false)
+		art := qr2String(q, *negative)
 		fmt.Println(art)
 		return
 	}
 
+	if *negative {
+		q.ForegroundColor, q.BackgroundColor = q.BackgroundColor, q.ForegroundColor
+	}
+
 	var png []byte
 	png, err = q.PNG(*size)
 	checkError(err)