ico

a tklib package to read and write icons from ICO ICL EXE and DLL files. see windows icons for more info. documentation is at ico

[perhaps someone could add a screenshot?]


MG just found this package again, and found it very useful. I was trying to add winico support to my app, and wanted to add an icon to the taskbar, but change the icon used periodically. Winico seems to only let you do this if all the icons you want to use are contained in one file (and mine weren't), but it was a simple case of

  package require ico
  set newico "new.ico"
  set old [list foo.ico bar.ico baz.ico]
  set i 0
  foreach x $old {
    ico::copyIcon $x 0 $newico $i
    incr i
  }

and I had a single file, new.ico, which contained all the icons from my other files.

AF says glad you found it useful, I just want to make this even easier:

  package require ico
  set newico "new.ico"
  set old [list foo.ico bar.ico baz.ico]
  foreach x $old {
    ico::copyIcon $x 0 $newico -1
  }

MG Cool, thanks. I didn't know you could use -1 like that.


jbr - There is a bug in the tklib 1.4 such that the padding on the and mask is incorrect. replace a line in ::ico::getAndMaskFromColors to look like:

       append l [string repeat 0 [expr {(32 - ([string length $l] % 32))%32}]]

I have filed a bug on sourceforge.

icoview2

TWu 2025-01-16 / 2025-01-21 - ico does not support completely icons with 256×256 in size or higher. Also including of png image inside of newer ICOns is not yet supported. Both problems we can detect on result "0×0" for the size and/or "21060" for the bpp (bits per pixel). This bpp is literally "DR" and comes from the PNG chunk name "IHDR" at bpp position, which ico seems read out without control/distinguishing BMP and PNG.
I propose to overwrite the useless "member-info" (like "0×0" or "21060bpp") by values from BMP DIB header (and may be later from embedded PNG and its header there). With this updated information we get better results on match on icon size/bpp.
Please see Open - Bug - tklib::ico - The ICO package does not handle 256x256 icons properly
I vote to correct both of the above points - including the reading of PNG width, height and bpp respectively, like the example but from different locations.

Testing with any "newer" ICOns of Windows Vista and above, ::ico::Show breaks at first PNG - regardless if correct images are after. Resolution in ico.tcl version 1.1.3, line 1428: replace "-$x" by "$name" (like it was done in line 1432 on transition from version 0.3.x to 1.y.z). Else it brings an internal error "no such variable" for 'x', which is known only in version 0.3.x iterating over "$icos". Would anybody file a bug for this on sourceforge, please? Thanks

@jbr and all others: John's 2012-01-06 reported bug is not yet solved - in both of the version variants. I found only the first half of the code sample in both source files, but all three are differently to each other.
Please see Open - Bug - tklib::ico - Padding on and mask rasters incorrect.
I vote to correct it.

How about the transparency / alpha channel? Tk has it, Img has it - native since 8.7 or latest release 9.0.1. See examples from PO for Fast image resizing, or others for Shrinking an image.

I'll provide solution for Open - Bug - tklib::ico - ico - Testsuite missing soon.

TWu 2025-02-01 - In preparation of the test suite I encounter that ::ico::Show
may stop to present the images after around the 300th ico file (depending on their hight),
and after additional around 10 ico files the framed labels are no longer shown.
This happens at least on Win 10 with ActiveTcl 8.6.4.1 (ico 1.0.5 from tklib 0.6).
This could be a general problem from availability of system resources (large passages in text or too big canvas).
Can someone place a new bug report on this, please? Thanks!

TWu 2025-02-04 - Using the actual routines from ::ico::* shows us:

  1. icons with a width/height not be a multiple of 4 (like 19 or 21 pixel) are shown with diagonal distorsion,
  2. icons with a bpp of 32 are shown with some artefacts (mostly black pixels instead of transparent ones)
    (Yet I've not checked if XOR or AND is the reason.),
  3. icons with a width/height bigger than 255 may be corrupted (as of wrong calculation with 8.0 in division and then call 'int'?)

I find no easy way to integrate PNG without changing the interface. For me there are some unusual constructs to optimate.
As long as PNG can occur in EXE, DLL etc. too the new functionality should be as flexible/integrated as before.
Are differences in/for different tcl/tk versions acceptable? Proposals are welcome!