Version 2 of Reading PNG Comments

Updated 2003-12-17 20:55:37

proc read_png_comments {file} {

    set fh [open $file r]
    fconfigure $fh -encoding binary -translation binary -eofchar {}
    if {[read $fh 8] != "\x89PNG\r\n\x1a\n"} { close $fh; return }
    set text {}

    while {[set r [read $fh 8]] != ""} {
        binary scan $r Ia4 len type
        set r [read $fh $len]
        if {[string length $r] != $len} { close $fh; return }
        if {$type ==  "tEXt"} {
            lappend text [split $r \x00]
        }
        seek $fh 4 current
    }
    close $fh
    return $text
 }

--AF Currently only supports uncompressed english comments. Todo list includes inflate support and unicode comments.


Category Graphics