Version 3 of Reading PNG Comments

Updated 2003-12-18 00:28:45

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
 }

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

Returns a list where each element is a comment. Each comment is a list consisting of 2 elements: the human readable keyword, and the text data.

--AF


Category Graphics