| img(3tk) | Img | img(3tk) |
img - Introduction to Img
package require Img ?2.0?
Img is a collection of format handlers for the Tk photo [https://www.tcl.tk/man/tcl9.0/TkCmd/photo.html] image type.
Sources and binaries of Img are available at SourceForge [https://sourceforge.net/projects/tkimg/].
The individual formats are described in more detail on their own pages.
Some image formats support storage of multiple pages in a file.
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.
There is currently no support for writing multi-page images.
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"]
Some image formats support an individual set of metadata dictionary keys. See the Tk photo [https://www.tcl.tk/man/tcl9.0/TkCmd/photo.html] image command for more information regarding image metadata.
This support is enabled, if Img is linked against Tk 8.7 or newer.
The following keys are supported:
Supported by formats img-bmp, img-jpeg, img-pcx, img-png, img-tiff.
Supported by formats img-bmp, img-jpeg, img-pcx, img-png, img-tiff.
Supported by formats img-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.
Example resolution specifications:
1.0: 1 inch 1i : 1 inch 1c : 1 centimeter 1m : 1 millimeter 1p : 1 point
img write out.png -format {png -resolution 300i 200c}
Some image formats support pixel values greater than storable in 8-bit integers.
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.
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 [https://www.tcl.tk/man/tcl9.0/TkLib/CrtPhImgFmt.html] 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)
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)
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)
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 (c) 1995-2024 Jan Nijtmans <nijtmans@users.sourceforge.net> Copyright (c) 2002-2024 Andreas Kupries <andreas_kupries@users.sourceforge.net> Copyright (c) 2003-2024 Paul Obermeier <obermeier@users.sourceforge.net>
| 2.0 | img |