imageName option ?arg ...?Option and the args determine the exact behavior of the command.
Those options that write data to the image generally expand the size of the image, if necessary, to accommodate the data written to the image, unless the user has specified non-zero values for the -width and/or -height configuration options, in which case the width and/or height, respectively, of the image will not be changed.
The following commands are possible for photo images:
When reading an image file or processing string data specified with the -data configuration option, the photo image code invokes each handler in turn until one is found that claims to be able to read the data in the file or string. Usually this will find the correct handler, but if it does not, the user may give a format name with the -format option to specify which handler to use. In this case, the photo image code will try those handlers whose names begin with the string specified for the -format option (the comparison is case-insensitive). For example, if the user specifies -format gif, then a handler named GIF87 or GIF89 may be invoked, but a handler named JPEG may not (assuming that such handlers had been registered).
When writing image data to a file, the processing of the -format option is slightly different: the string value given for the -format option must begin with the complete name of the requested handler, and may contain additional information following that, which the handler can use, for example, to specify which variant to use of the formats supported by the handler. Note that not all image handlers may support writing transparency data to a file, even where the target image format does.
Image data in the default string format is a (top-to-bottom) list of scan-lines, with each scan-line being a (left-to-right) list of pixel data. Every scan-line has the same length. The color and, optionally, alpha value of each pixel is specified in any of the forms described in the COLOR FORMATS section below.
Normally, the number of colors allocated is chosen based on the depth of the window. For example, in an 8-bit PseudoColor window, the photo image code will attempt to allocate seven shades of red, seven shades of green and four shades of blue, for a total of 198 colors. In a 1-bit StaticGray (monochrome) window, it will allocate two colors, black and white. In a 24-bit DirectColor or TrueColor window, it will allocate 256 shades each of red, green and blue. Fortunately, because of the way that pixel values can be combined in DirectColor and TrueColor windows, this only requires 256 colors to be allocated. If not all of the colors can be allocated, the photo image code reduces the number of shades of each primary color and tries again.
The user can exercise some control over the number of colors that a photo image uses with the -palette configuration option. If this option is used, it specifies the maximum number of shades of each primary color to try to allocate. It can also be used to force the image to be displayed in shades of gray, even on a color display, by giving a single number rather than three numbers separated by slashes.
It is valid to set any key in the metadata dict. A format driver will ignore keys it does not handle.
# These lines should be called once image create photo untiled -file "theFile.ppm" image create photo tiled # These lines should be called whenever .someWidget changes # size; a <Configure> binding is useful here set width [winfo width .someWidget] set height [winfo height .someWidget] tiled copy untiled -to 0 0 $width $height -shrink
The PNG image loader allows the application of an additional alpha factor during loading, which is useful for generating images suitable for disabled buttons:
image create photo icon -file "icon.png" image create photo iconDisabled -file "icon.png" \ -format "png -alpha 0.5" button .b -image icon -disabledimage iconDisabled
Create a green box with a simple shadow effect
image create photo foo # Make a simple graduated fill varying in alpha for the shadow for {set i 14} {$i > 0} {incr i -1} { set i2 [expr {$i + 30}] foo put [format black#%x [expr {15-$i}]] -to $i $i $i2 $i2 } # Put a solid green rectangle on top foo put #F080 -to 0 0 30 30