Created
September 7, 2019 19:51
-
-
Save scottleedavis/25f5e7d1b97dcb8964b74712cfbc6a29 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 ( | |
"bufio" | |
"bytes" | |
"fmt" | |
"gopkg.in/auyer/steganography.v2" | |
"image" | |
"os" | |
) | |
func main() { | |
inFile, err := os.Open("./assets/pre_test.png") // opening file | |
if err != nil { | |
fmt.Println("unable to open file") | |
} | |
defer inFile.Close() | |
reader := bufio.NewReader(inFile) // buffer reader | |
img, _, err := image.Decode(reader) | |
if err != nil { | |
fmt.Println("ERROR: original image is corrupt " + err.Error()) | |
return | |
} | |
w := &bytes.Buffer{} | |
err = steganography.Encode(w, img, []byte("this is a watermark")) | |
if err != nil { | |
fmt.Println(err.Error()) | |
} | |
reader = bufio.NewReader(w) | |
img, _, err = image.Decode(reader) | |
if err != nil { | |
fmt.Println(err.Error()) | |
} | |
sizeOfMessage := steganography.GetMessageSizeFromImage(img) | |
msg := steganography.Decode(sizeOfMessage, img) | |
fmt.Println("**** " + string(msg)) | |
} |
@auyer I tested with test.png and it worked, however, I have uploaded pre_test.png (a png without the watermark already) and it doesn't. Does using pre_test.png correctly work on your system?
perhaps something is corrupted in the pre_test.png image?
I will try out the jpg approach now. 👍
jpg test with decode.go, with above approach has this output currently.
$ go run decode.go ./assets/test.jpg
panic: runtime error: slice bounds out of range
goroutine 1 [running]:
gopkg.in/auyer/steganography%2ev2.decodeRGBA(0xffffffff00000004, 0xc0000b6080, 0xc0000b6080, 0x4, 0x8)
/Users/scottd/go/pkg/mod/gopkg.in/auyer/steganography.v2@v2.0.0-20190427051610-2664780d40a3/steganography.go:180 +0x5a8
gopkg.in/auyer/steganography%2ev2.decode(0xffffffff00000004, 0x1113040, 0xc00014e080, 0xc0000aa000, 0x1113040, 0xc00014e080)
/Users/scottd/go/pkg/mod/gopkg.in/auyer/steganography.v2@v2.0.0-20190427051610-2664780d40a3/steganography.go:203 +0x53
gopkg.in/auyer/steganography%2ev2.Decode(...)
/Users/scottd/go/pkg/mod/gopkg.in/auyer/steganography.v2@v2.0.0-20190427051610-2664780d40a3/steganography.go:217
main.main()
/Users/scottd/workspace/mattermost-plugin-watermark/decode.go:44 +0x296
exit status 2
it must be the image (for the png issue)... it is working with a new png.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ran this with both images in your assets folder and it worked fine.
In the case of the
.jpg
image, it will work if:Using the
"image/jpeg"
module to decodeimg, err := jpeg.Decode(reader)
Usage of a init import paired with the default decoding: