Runnable Images

2008-07-15 - Stu
A "runnable image" is an image appended to a little bit of Tcl image viewing code that displays the image when executed.

#! /bin/sh
# \
exec tclsh8.5 "$0" ${1+"$@"}
set f [open $argv0]
fconfigure $f -eofchar \x1a
read $f
seek $f 1 current
fconfigure $f -translation binary
set d [read $f]
close $f
package require Tk
image create photo i1 -data $d
pack [label .l -image i1]
# EOF
^Z

There must be a Control-Z (0x1a) at the end of the file.
Then, (assuming it's saved as 'i.tcl') in a shell:

$ cat i.tcl myimage.gif > viewmyimage.tcl
$ chmod u+x viewmyimage.tcl
$ ./viewmyimage.tcl
or
$ tclsh viewmyimage.tcl

This could be used for a single-file slideshow, Quick Slide Show for example.