Version 22 of windows icons

Updated 2003-10-25 03:40:23

--AF 08-08-03

this package provides functions for reading and writing windows icons to ICO, EXE, DLL, and ICL files.

the code has grown to become a little large for posting here. it is all available for download at

http://www.fearme.com/misc/programs.cgi?type=tcltk&file=icons

[IconStats file type] returns info on the icons within the file. there is one list element per icon. each element consists of 3 numbers, the width, height, and color depth of the icon. type must be one of ICO, EXE

[getIconImage file type index] returns the name of an image containing the icon named by file and index. index starts at 0, see IconStats.

[getIconColors file type index] returns a list where each element is a row of the image. each row is a list where each element is a pixel. each pixel is in the familiar form #RRGGBB. an empty pixel denotes transparency. the image rows are in a bottom to top order.

[writeIcon file type index bpp colors] writes an icon to the named file. colors is either a list in the above format, with the exception that each pixel is of the form "R G B" where each number has the range 0 to 255, or it is the name of an image from which to extract the data. bpp is the color depth to write the icon with. supported depths are 1, 4, 8, 24, and 32. if you select 1, 4, or 8 and your image has too many colors an error will be generated. index may be specified as one higher than the number of icons currently in the file. indexes outside this range will generate an error. when writing an exe you may only replace an icon with one of the same size and color depth. you cannot add new icons to exes.

[translateColors colors] this function will change a list of colors in the #RRGGBB format to the "R G B" format required by [writeIcon]

[transparentColor image color] sets every pixel that is color in Tk image image to be transparent. color may be either the #RRGGBB or the "R G B" format.

[EXEtoICO exe ico] creates a new .ico file with the name ico containing every icon from the exe exe. this function is much faster than extracting and writing the icons using the other functions.

some keywords for searches: ico icl


Vince adds - this is great! I particularly like the code to adjust the version/name/etc of a tclkit. I do notice, however, that there seem to be two different 'File version' fields, one of which I can set, but the other of which I can't. Is that true?


CF - This is the missing link for turning a Starpack into a branded application with your Icon.

Here's a short script that accepts a gif image as the command line argument, and creates a tclkit.ico file that can be used to create a Starpack with custom icons, as decribed at http://www.equi4.com/267 . This script runs on a Linux/Unix system with ImageMagick installed. The initial .gif image must be square.

 source icons.tcl
 set orig [lindex $argv end]
 set icoFile tclkit.ico

 pack [label .l -textvariable state]

 image create photo temp48 -file $orig
 ::ico::writeIcon $icoFile ICO 0 8 temp48

 set pos -1
 foreach s {48 32 16} {
   set name [format "temp%s" $s]
   set geom [format %dx%d $s $s]
   set state "$geom @ 256"; update idle;

   exec convert -geometry $geom -colors 256 $orig $name.gif
   image create photo $name -file $name.gif
   ::ico::writeIcon $icoFile ICO [incr pos] 8 $name

   set state "$geom @ 16"; update idle;
   exec convert -geometry $geom -colors 16 $orig r$name.gif
   image create photo r$name -file r$name.gif
   ::ico::writeIcon $icoFile ICO [incr pos] 4 r$name
   file delete $name.gif r$name.gif
 }

 set state "DONE - Icon file is $icoFile"
 pack [button .b -text "EXIT" -command exit]

Category GUI

Category Package