ico(n)
π ico(n) β Windows ICO handling π
Bestie, welcome to the ico(n) page. Itβs giving Windows icon main-character energy, and weβre gonna read and write them. No cap. π
πΈ NAME πΈ
ico β reading and writing Windows icons, periodt. π
β¨ SYNOPSIS β¨
package require Tcl 8.4
package require ico ?1.0.5?
::ico::icons file ?option value...?
::ico::iconMembers file name ?option value...?
::ico::getIcon file name ?option value...?
::ico::getIconByName file name ?option value...?
::ico::getFileIcon file ?option value...?
::ico::writeIcon file name depth data ?option value...?
::ico::copyIcon file index file2 index2 ?option value...?
::ico::EXEtoICO file ?dir?
::ico::clearCache ?file?
::ico::transparentColor image color
::ico::Show file ?option value...?
π¦ DESCRIPTION π¦
This package gives you functions for reading and writing Windows icons from ICO, EXE, DLL, ICL, and BMP files. In this module, an icon is a visual representation of an object. An icon consists of one or more images, usually with varying resolution and color depth. Each icon and image has a resource identifier, which may be a text string or a positive integer value. Most commands use this identifier to specify which icon or image to operate on. Icon behavior? Lowkey iconic. π
π API π
π οΈ ::ico::icons file ?option value...?
Returns a list of icons found in file, where each element is the name or numeric ID. Recognizes the following options:
-type fileFormatβ the file-format option, bestie. β¨
π οΈ ::ico::iconMembers file name ?option value...?
Returns a list of images that make up the icon with ID name. Each element is itself a sublist in the format {name width height bpp}. Recognizes the following options:
-type fileFormatβ file-format selector. π
π οΈ ::ico::getIcon file name ?option value...?
Extracts the icon with ID name from file. The default -format is image, which will return the name of a Tk image containing the icon. The resolution and color depth are selected with the ?-res?, ?-bpp?, and ?-exact? options. If -exact is specified and there is no exact match, an error is thrown. Optionally, -image may be used to specify the name of the Tk image that is created.
If -format is colors, then a list of color names in the #RRGGBB format is returned. Each list element is a horizontal row. Each horizontal row contains a list of colors for all the pixels in that row from left to right. If -format is name, then the resource name of the image chosen is returned. This is useful for calling writeIcon or getIconByName. Recognizes the following options:
-type fileFormatβ file-format option. π-format valueβ output format selector, iykyk. π«-image valueβ name of the Tk image to create. πΌοΈ-res valueβ resolution selector. π-bpp valueβ color-depth selector. π¨-exact valueβ exact-match option; if specified with no exact match, it throws an error. π
π οΈ ::ico::getIconByName file name ?option value...?
Extracts the image with ID name from file. This name should be the name of a specific image as returned by ::ico::iconMembers, not an icon name returned from ::ico::icons. If there is no matching resource ID in file, an error is thrown. Recognizes the following options:
-type fileFormatβ file-format selector. π¦-format valueβ output format selector. π
π οΈ ::ico::getFileIcon file ?option value...?
This command is only functional when running under Windows. It reads the Windows registry to determine the display icon for file as it would appear in Explorer or similar. file does not need to exist and may also be specified as a file extension with a leading dot. If file is a directory or you specify the special name Folder, then the icon representing a folder is returned. This command takes the same arguments and usage as getIcon:
-format valueβ output format selector. β¨-image valueβ name of the Tk image to create. πΌοΈ-res valueβ resolution selector. π-bpp valueβ color-depth selector. π¨-exact valueβ exact-match option; if specified with no exact match, it throws an error. π
π οΈ ::ico::writeIcon file name depth data ?option value...?
Writes an image to file. name is the resource identifier of the image in file to write.
When writing to an EXE, DLL, or ICL file, you may only overwrite existing icons with an icon of the same dimensions and color depth. No icons may be added to these file types. Important, bestie. π¨
When writing to BMP, the name is ignored, as this type can contain only one image. This means if the file already existed, it is completely overwritten. π
When writing to an ICO or ICODATA file, if the name specified does not exist, then an image is appended and will be named the next in sequence (the specified name is ignored). Images in ICO and ICODATA files may be overwritten with differing dimensions or color depths. Note that you will get strange results when displaying icons if you fail to change every image which makes up a given icon. π
Arg tea:
integer depth (in)β this argument must have a value of1,4,8,24, or32. Ifdatahas more colors than the color depth allows, an error will be generated. π΅options data (in)β this argument is either a list of colors in the format returned by::ico::getIcon -format colorsor the name of a Tk image. π¨
Recognizes the following options:
-type fileFormatβ file-format option. π οΈ
π οΈ ::ico::copyIcon file index file2 index2 ?option value...?
Copies the icon at index in file to index2 in file2. Slay, copy-paste but for icons. π
-fromtype fileFormatβ source file-format option. π€-totype fileFormatβ destination file-format option. π₯
π οΈ ::ico::EXEtoICO file ?dir?
Extracts all icons from the executable file to ICO files placed in dir. ?dir? defaults to the directory file is located in. Icon files will be named in the form file-ID.ico, where ID is the icon resource identifier. β¨
-type fileFormatβ file-format option. π
π οΈ ::ico::clearCache ?file?
The ::ico::getIconList command caches icon offsets inside EXE, DLL, ICL, and ICO files in order to speed up extraction. This command clears that cache for the specific ?file? or all files. Cleanup era. π§Ή
π οΈ ::ico::transparentColor image color
If image is a single word, it is assumed to be the name of a Tk image. All pixels matching color in the image will be set transparent. Alternatively, image may be a color list, in which case a modified list is returned. Transparency? Obsessed. π«Ά
π οΈ ::ico::Show file ?option value...?
Application-level command which displays a window showing all the icons in file and their name. Main-character GUI moment. π
-type fileFormatβ file-format option. π-parent pathNameβ parent path-name option. πͺ
π₯ EXAMPLE π₯
button .explore -image [::ico::getIcon explorer.exe 0 -name explore -res 16 -bpp 8]
set i [lsearch -inline [::ico::iconMembers tclkit.exe 0] {* 32 32 8}]
set colorlist [::ico::getIconByName tclkit.exe [lindex $i 0] -format colors]
π LIMITATIONS π
Icons may not be added or removed from file types other than ICO. Icons in these files may only be replaced with icons of the same dimensions and color depth. No cap, thatβs just the rule. π«
Icons of 8bpp or lower must include black in the pallete; this means if your icon does not have black in it, you will need to leave a color free so that it may be included by writeIcon. π
There is currently no way to read alpha channel information from 32bpp icons. The tea is tragic. β
Tk images do not have an alpha channel, so the only way to write a true 32bpp icon is from a color list. Writing a 32bpp icon from a Tkimage is identical to writing a 24bpp icon. π
π BUGS, IDEAS, FEEDBACK π
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category ico of the Tklib Trackers [http://core.tcl.tk/tklib/reportlist]. Please also report any ideas for enhancements you may have for either package and/or documentation. Weβre listening, bestie. π«Ά
π KEYWORDS π
dll, entry, exe, ico, icon β the whole keyword squad. β¨
Signed off with love by tklib version 1.0.5, manual page ico(n) ππβ¨
π¦ where this page comes from
- alpine 3.24: tk-lib-doc 0.7-r0 Β· TCL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms