Version 0 of Creating image photo data from GIF files

Updated 2002-01-24 14:06:58

Ever want to embed your images directly into your Tcl code, eliminating the need to carry a bunch of GIF files along with your application? Jeff Godfrey writes on comp.lang.tcl, "Yes, this can be done, and quite simply too..."

1. First, you must convert your gif images to base64 encoded data. You can do this with using the base64 package included in tcllib:

 package require base64
 set fileID [open "mypic.gif" RDONLY]
 fconfigure $fileID -translation binary
 set rawData [read $fileID]
 close $fileID
 set encodedData [base64::encode $rawData]

(Using the above, it's quite simple to write a program that will encode a group of gif files...) The "encodedData" variable will now contain the image data encoded as a string that can stored in a variable in your script.

2. Now, to use the encoded image, just convert it to a "photo" and pass it to the appropriate widget:

 set imageData "<base64 encoded data string>"
 set myPic [image create photo -data $imageData]
 label .l1 -image $myPic
 pack .l1

So, basically:

1. Encode all of your images and store the encoded strings in your script

2. Convert the encoded strings to photo images and use as needed (as above).

3. Season to taste...