-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PNG image inclussion #41
Comments
What specifically are you needing in PNG files? If you have a recommendation we can certainly consider it. |
I am needing exif and xmp metadata from the image |
You should be able to download this PNG and see the exif using
|
That PNG file does not contain EXIF data. The I know this doesn't solve your problem, but I wanted to point out that the specific PNG sample doesn't contain EXIF data. |
Hi @abrander thanks for pointing that out. At least I now have a direction to look into as I have been trying different ways and nothing is working because I didn't know the actual root cause. I will be looking into the PNG I found a resource http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html#C.tEXt |
You can have a look at the PNG parser in #46, that parser can be modified to extract text chunks instead of exif chunks simply by replacing the |
@abrander Thanks I somehow figured it out based on your comment. Is this correct? package main
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"os"
)
func ScanPngHeader(r io.ReadSeeker) (result string, err error) {
// 5.2 PNG signature
const signature = "\x89PNG\r\n\x1a\n"
// 5.3 Chunk layout
const crcSize = 4
// 8 is the size of both the signature and the chunk
// id (4 bytes) + chunk length (4 bytes).
// This is just a coincidence.
buf := make([]byte, 8)
var n int
n, err = r.Read(buf)
if err != nil {
print("error: ", err)
return "", err
}
if n != len(signature) || string(buf) != signature {
print("invalid PNG signature")
return "", errors.New("invalid PNG signature")
}
for {
n, err = r.Read(buf)
if err != nil {
break
}
if n != len(buf) {
break
}
length := binary.BigEndian.Uint32(buf[0:4])
chunkType := string(buf[4:8])
switch chunkType {
case "tEXt":
print("found tEXt chunk\n")
data := make([]byte, length)
_, err := r.Read(data)
if err != nil {
return "", err
}
separator := []byte{0}
separatorIndex := bytes.Index(data, separator)
if separatorIndex == -1 {
return "", errors.New("invalid tEXt chunk")
}
return string(data[separatorIndex+1:]), nil
default:
// Discard the chunk length + CRC.
_, err := r.Seek(int64(length+crcSize), io.SeekCurrent)
if err != nil {
return "", err
}
}
}
return "", nil
}
func main() {
imgFile, err := os.Open("test.png")
if err != nil {
panic(err)
}
defer imgFile.Close()
text, _ := ScanPngHeader(imgFile)
fmt.Println("text: ", text)
} |
@geocine and @maggie-vegaa. Currently working on updates in develop branch, this has been included. Does this solve your issue? |
Yes @evanoberholster. Not directly but yes when EXIF is concerned. |
This looks good. A few notes, thou:
I hope this helps you solve your problem. Unless @evanoberholster wants to add tEXt-reading to this package, I think we should continue the conversation by email, if you have further comments. |
Thanks @abrander for the help. I don't want to pollute this issue further. |
Hi! Thanks for making this package, it is very useful, i was wondering if there is a chance to add PNG images into the library, i was really looking for it
The text was updated successfully, but these errors were encountered: