proc read_jpg_comment {file} { set fh [open $file r] fconfigure $fh -encoding binary -translation binary -eofchar {} if {[read $fh 2] != "\xFF\xD8"} { close $fh; return } set c 0 while {$c != "\xDA"} { while {[set c [read $fh 1]] != "\xFF" && $c != ""} {} while {[set c [read $fh 1]] == "\xFF"} {} binary scan [read $fh 2] cc l1 l2 set len [expr {$l1<<8|$l2}] if {$c == "\xFE"} { set com [read $fh [expr {$len - 2}]] close $fh return $com } elseif {$c == "" || $len < 2} { break } else { seek $fh [expr {$len - 2}] current } } close $fh } ---- --[AF] ---- [Category Graphics]