-
Notifications
You must be signed in to change notification settings - Fork 0
/
stegotest.go
72 lines (62 loc) · 1.65 KB
/
stegotest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// https://www.socketloop.com/tutorials/golang-get-rgba-values-of-each-image-pixel
// https://stackoverflow.com/questions/33186783/get-a-pixel-array-from-from-golang-image-image
// https://socketloop.com/tutorials/golang-convert-integer-to-binary-octal-hexadecimal-and-back-to-integer
// https://dev.to/andyhaskell/how-i-made-a-slick-personal-logo-with-go-s-standard-library-29j9
package main
import (
"fmt"
"flag"
"image"
"image/color"
"image/png"
// ^ https://golang.org/pkg/image/
"os"
//"strconv"
//"io/ioutil"
)
func decodeImg(myImage string) image.Image {
file, err := os.Open(myImage)
if err != nil {
fmt.Println(err)
}
defer file.Close()
data, _, err := image.Decode(file)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
return data
}
func recolor(data image.Image, bounds image.Rectangle) *image.RGBA {
recolored := image.NewRGBA(bounds)
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
colors := data.At(x, y)
r, g, b, a := colors.RGBA()
newColor := color.RGBA{R: uint8(r), G: uint8(g), B: uint8(b), A: uint8(a)}
recolored.Set(x, y, newColor)
}
}
return recolored
}
func main() {
var image string
var output string
flag.StringVar(&image, "f", "", "PNG File to use")
flag.StringVar(&output, "o", "", "Output file")
flag.Parse()
// Decode image into something useable and define bounds
data := decodeImg(image)
bounds := data.Bounds()
// Create an outfile
out, err := os.Create(output)
if err != nil {
fmt.Println(err)
}
defer out.Close()
// Make the new image
recolored := recolor(data, bounds)
if err := png.Encode(out, recolored); err != nil {
fmt.Println(err)
}
}