img(n)
π img(n) β Introduction to Img π
okay bestie, gather round, because this is the Img manual page and it's lowkey a whole buffet of image formats πβ¨
β¨ SYNOPSIS β¨
package require Img ?2.1?
that's it. that's the whole vibe. one line and you're in π«Ά
πΈ DESCRIPTION πΈ
Img is a collection of format handlers for the Tk photo image type. no cap, that's the entire personality β it makes Tk's photo images speak a million different file formats π
Sources and binaries of Img are available at SourceForge, so if you need to go get them, they're right there π
The individual formats are described in more detail on their own pages, because obviously they each deserve their own moment π
bmpβ Windows bitmap format. Seeimg-bmp.dted*β Digital Terrain Elevation Data format. Seeimg-dted.flir*β FLIR FPF Public Image format. Seeimg-flir.gif*β Graphics Interchange Format. Seeimg-gif.icoβ Windows icon format. Seeimg-ico.jpegβ Joint Picture Experts Group format. Based on libjpeg 9f. Seeimg-jpeg.pcxβ Paintbrush format. Seeimg-pcx.pixmapβ Pixmap image type. While the other formats are handlers for the Tk photo image type, this is a new image type for Tk. Seeimg-pixmap. (not me, a whole new image type, main character energy fr fr π)pngβ Portable Network Graphics format. Based on libpng 1.6.47. Seeimg-png.ppmβ Portable pixmap format. Seeimg-ppm.ps*β Postscript and PDF format. Requires an external application,ghostviewfor its operation. Seeimg-ps.raw*β Raw data format. Seeimg-raw.sgiβ Silicon Graphics format. Seeimg-sgi.sunβ Sun raster format. Seeimg-sun.tgaβ Truevision Targa format. Seeimg-tga.tiffβ Tagged Image File Format. Based on libtiff 4.7.0. Seeimg-tiff.windowβ Tk window as photo image. Seeimg-window.xbmβ X Windows Bitmap format. Seeimg-xbm.xpmβ X Windows Pixmap format. Seeimg-xpm.
π NOTES π
- [1] Img version 2 only works with Tcl/Tk 8.6 or newer. If using an older Tcl/Tk version, use the lastest Img 1.4 version.
- [2] Formats marked with
*are not loaded when doing apackage require Img, but must be loaded explicitly viapackage require img::FORMAT.
π yes bestie, the starred ones are the "you gotta ask nicely" formats. they don't just show up.
π¦ MULTI-PAGE IMAGES π¦
Some image formats support storage of multiple pages in a file. iconic behaviour, honestly π
Supported by formats img-gif, img-ico, img-ps, img-tiff.
A specific page can be extracted using the -index option. Index 0 specifies the first page. (yes, zero-indexed, we love a counting-from-zero moment π)
There is currently no support for writing multi-page images. sad but true π
The number of pages of an image file can either be retrieved using metadata key numpages (see chapter Image Metadata) or by checking different -index values.
For example, GIF images can have multiple pages in one file. The metadata dictionary key numpages is not supported for GIF images, as this property cannot be extracted fast. πβοΈπ¨
If you need to know the number of pages, use code like in the following example:
proc CheckIndex { fileName fmt ind } {
set retVal [catch {image create photo -file $fileName -format "$fmt -index $ind"} phImg]
if { $retVal == 0 } {
image delete $phImg
return true
}
return false
}
proc GetNumPages { fileName fmt } {
if { [CheckIndex $fileName $fmt 1] } {
set ind 5
while { [CheckIndex $fileName $fmt $ind] } {
incr ind 5
}
incr ind -1
while { ! [CheckIndex $fileName $fmt $ind] } {
incr ind -1
}
return [expr { $ind + 1 }]
}
return 1
}
# Determine the number of pages of an animated GIF.
set numPages [GetNumPages $imgFile "gif"]
π that binary-search-ish walk? obsessed. it's giving "I don't know how many pages but I WILL find out".
π IMAGE METADATA π
Some image formats support an individual set of metadata dictionary keys. See the Tk photo image command for more information regarding image metadata.
This support is enabled, if Img is linked against Tk 8.7 or newer. (link it, bestie, you deserve it β¨)
The following keys are supported:
DPIβ Horizontal image resolution in dots per inch as double value. Supported by formatsimg-bmp,img-jpeg,img-pcx,img-png,img-tiff.aspectβ Aspect ratio defined as horizontal size divided by vertical size as double value. Supported by formatsimg-bmp,img-jpeg,img-pcx,img-png,img-tiff.numpagesβ The number of pages in an image file. Supported by formatsimg-ico,img-tiff.
All formats supporting image resolution (DPI and aspect) have the following format options for writing these values without explicitly setting the metadata dictionary:
-resolution -xresolution -yresolution.
- [1] Option
-resolutionallows specifying both horizontal and vertical resolution values. - [2] If not using option
-resolution, options-xresolutionand-yresolutionmust both be specified. Otherwise no resolution information is written. - [3] Resolution values specified with any of the above options overwrite the corresponding metadata dictionary values.
- [4] The resolution values can be specified as double values as documented with function
Tk_GetPixels.
Example resolution specifications:
1.0: 1 inch
1i : 1 inch
1c : 1 centimeter
1m : 1 millimeter
1p : 1 point
Example writing PNG image with horizontal resolution of 300 inches and vertical resolution of 200 centimeters:
img write out.png -format {png -resolution 300i 200c}
πΈ look at those cute little unit suffixes. 300i 200c? she's got range, she's got units, she ate π
π₯ VALUE MAPPING π₯
Some image formats support pixel values greater than storable in 8-bit integers. big numbers, big energy π§
- The following formats support 16-bit integer pixel values:
img-dted,img-ppmimg-raw. - The following formats support floating point pixel values:
img-flir,img-raw.
To map these values to 8-bit integer values as needed for a Tk photo, two different algorithms are implemented in Img:
A simple MinMax algorithm and an advanced Automatic Gain Control (AGC) algorithm using histogram equalization.
The default for all supported formats is to use the MinMax algorithm, which determines the minimum and maximum values of the image automatically. π (set it and forget it, she does the math for you)
π MATCHING ORDER π
okay this is the part where it gets spicy πΆοΈ
When reading images without specifying the format (using option -format), the match functions of the available formats are tried in reversed order as registered. So, the handlers of the Img package are called before the handlers of the Tk core. The Tk core registers the following handlers: GIF, PNG, PPM, SVG, DEFAULT.
In Tk 8.7 a new format handler structure (Tk_PhotoImageFormatVersion3) was introduced to handle the new metadata information. All old handlers (Tk_PhotoImageFormat) are called before calling the new Format3 handlers.
See manual page of function Tk_CreatePhotoImageFormat for a detailed description of the handler struture and matching functions.
The resulting matching order is best explained by an example:
package require Tk
package require Img
package require img::raw (Format2 Img handler)
Note, that the package require Img command actually calls the following statements:
package require img::window (Format2 Img handler)
package require img::tga (Format2 Img handler)
package require img::ico (Format3 Img handler)
package require img::pcx (Format3 Img handler)
package require img::sgi (Format2 Img handler)
package require img::sun (Format2 Img handler)
package require img::xbm (Format2 Img handler)
package require img::xpm (Format2 Img handler)
package require img::jpeg (Format3 Img handler)
package require img::png (Format3 Img handler)
package require img::tiff (Format3 Img handler)
package require img::bmp (Format3 Img handler)
package require img::ppm (Format2 Img handler)
The order of calling the match functions is therefore as follows:
Match format raw (Format2 Img handler)
Match format ppm (Format2 Img handler)
Match format xpm (Format2 Img handler)
Match format xbm (Format2 Img handler)
Match format sun (Format2 Img handler)
Match format sgi (Format2 Img handler)
Match format tga (Format2 Img handler)
Match format window (Format2 Img handler)
Match format svg (Format2 Tk handler)
Match format ppm (Format2 Tk handler)
Match format default (Format2 Tk handler)
Match format bmp (Format3 Img handler)
Match format tiff (Format3 Img handler)
Match format png (Format3 Img handler)
Match format jpeg (Format3 Img handler)
Match format pcx (Format3 Img handler)
Match format ico (Format3 Img handler)
Match format png (Format3 Tk handler)
Match format gif (Format3 Tk handler)
β the waypackage require Imgis quietly firing off a whole roster ofpackage requirecalls? she's a manager. she delegates. periodt.
π SEE ALSO π
img, img-bmp, img-dted, img-flir, img-gif, img-ico, img-jpeg, img-pcx, img-pixmap, img-png, img-ppm, img-ps, img-raw, img-sgi, img-sun, img-tga, img-tiff, img-window, img-xbm, img-xpm
π COPYRIGHT π
Copyright (c) 1995-2025 Jan Nijtmans <nijtmans@users.sourceforge.net>
Copyright (c) 2002-2025 Andreas Kupries <andreas_kupries@users.sourceforge.net>
Copyright (c) 2003-2025 Paul Obermeier <obermeier@users.sourceforge.net>
and that's the whole page bestie!! this is img(n) from Img version 2.1 β big love to Jan Nijtmans, Andreas Kupries and Paul Obermeier for making Tk see basically every image format ever, ily π«Άπ slay, go read an image, bye!! β¨πΈπ¦
π¦ where this page comes from
- fedora 43: tkimg 2.1.1-1.fc43 Β· TCL AND libtiff AND HPND-Pbmplus AND URT-RLE AND IJG AND libpng-2.0 AND libpng-1.6.35 AND (BSD-4-Clause OR GPL-2.0-or-later) AND BSD-4-Clause AND MIT AND Zlib
- fedora 43: tkimg 2.1.1-1.fc43 Β· TCL AND libtiff AND HPND-Pbmplus AND URT-RLE AND IJG AND libpng-2.0 AND libpng-1.6.35 AND (BSD-4-Clause OR GPL-2.0-or-later) AND BSD-4-Clause AND MIT AND Zlib
- fedora 44: tkimg 2.1.0-2.fc44 Β· TCL AND libtiff AND HPND-Pbmplus AND URT-RLE AND IJG AND libpng-2.0 AND libpng-1.6.35 AND (BSD-4-Clause OR GPL-2.0-or-later) AND BSD-4-Clause AND MIT AND Zlib
- fedora 44: tkimg 2.1.0-2.fc44 Β· TCL AND libtiff AND HPND-Pbmplus AND URT-RLE AND IJG AND libpng-2.0 AND libpng-1.6.35 AND (BSD-4-Clause OR GPL-2.0-or-later) AND BSD-4-Clause AND MIT AND Zlib
- fedora 44: tkimg 2.1.1-1.fc44 Β· TCL AND libtiff AND HPND-Pbmplus AND URT-RLE AND IJG AND libpng-2.0 AND libpng-1.6.35 AND (BSD-4-Clause OR GPL-2.0-or-later) AND BSD-4-Clause AND MIT AND Zlib
- fedora 44: tkimg 2.1.1-1.fc44 Β· TCL AND libtiff AND HPND-Pbmplus AND URT-RLE AND IJG AND libpng-2.0 AND libpng-1.6.35 AND (BSD-4-Clause OR GPL-2.0-or-later) AND BSD-4-Clause AND MIT AND Zlib
- nixos 26.05: tkimg 2.1.1
- nixpkgs unstable: tkimg 2.1.1
- Copyright (c) 1995-2025 Jan Nijtmans <nijtmans@users\&.sourceforge\&.net>
- Copyright (c) 2002-2025 Andreas Kupries <andreas_kupries@users\&.sourceforge\&.net>
- Copyright (c) 2003-2025 Paul Obermeier <obermeier@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms