1: #! /usr/bin/env tclsh 2: 3: package require Tk 4: package require base64 5: 6: if {[llength $argv] != 2} { 7: puts stderr "Usage: convertimg2tcl <inputfile> <outputfile>" 8: exit 1 9: } 10: 11: set inputfile [lindex $argv 0] 12: set outputfile [lindex $argv 1] 13: 14: switch -glob -- $inputfile { 15: "*.gif" { 16: set fd [open $inputfile r] 17: } 18: "*.ppm" { 19: set fd [open $inputfile r] 20: } 21: default { 22: set fd [open "|convert $inputfile ppm:-" r] 23: } 24: } 25: fconfigure $fd -translation binary 26: set imagedata [read $fd] 27: close $fd 28: 29: set imagename [file rootname [file tail $inputfile]] 30: 31: set ofd [open $outputfile w] 32: puts $ofd {#! /usr/bin/env wish} 33: puts $ofd {} 34: puts $ofd "namespace eval images {}" 35: puts $ofd "image create photo ::images::$imagename -data \{[base64::encode $imagedata]\}" 36: close $ofd 37: 38: exit 0 39: 40: # Display image 41: set image [image create photo -data $imagedata] 42: canvas .bg -width [image width $image] -height [image height $image] -highlightthickness 0 43: wm geometry . [image width $image]x[image height $image] 44: .bg create image 0 0 -anchor nw -image $image 45: place .bg -x 0 -y 0 |