image data
A command of a photo: gives its pixels as colors or in a format.
IMAGENAME data ?-background COLOR? ?-format FORMAT? ?-from X1 Y1 ?X2 Y2?? ?-grayscale?
Description
With no -format, gives a list of rows, each a text of colors as #rrggbb. With -format ppm, -format png, or -format gif, gives the bytes of that format. The text of -format starts with the name of the format, in any case, and the rest is ignored: gif89a names GIF.
A GIF has a table of up to 256 colors, in the order of their first pixel, and a region with more gives the error too many colors. Index 0 of the table is for the pixels with an alpha of 0, and a pixel with some alpha keeps its color, unless the result has no alpha left (see below).
-from gives the region: from X1 Y1 to the edges, or to X2 Y2 with the end not counted. A missing Y is the X of its corner, as in Tk 8.6. -background puts each pixel on COLOR by its alpha, and -grayscale turns each color to a gray, with the pixel and COLOR gray before the blend. As in Tk 8.6, the region decides which of the two apply: a region with a pixel of alpha below 255 gets the background and the gray, and a region with none gets only the gray; a region of one column gets the gray only when it has such a pixel and no -background, and gets neither option when both are given. A GIF of a region with no alpha left, from the background or from the gray of a region with no alpha, has no index for clear pixels. An option name can be the start of one name.
Returns
A list of rows of colors, or the bytes of the format.
Examples
% image create photo d -width 3 -height 2
> d put {{#ff0000 #00ff00 #0000ff} {#808080 #ffffff #000000}}
> d data -from 1 0
{#00ff00 #0000ff} {#ffffff #000000}
% image create photo d2 -width 2 -height 1
> d2 put {{#ff0000 #0000ff}}
> list [d2 data -grayscale] [binary encode hex [d2 data -format ppm]]
{{#585858 #282828}} 50360a3220310a3235350aff00000000ff
% image create photo d5 -width 2 -height 1
> d5 put {{#ff0000 #0000ff}}
> binary encode hex [d5 data -format gif]
47494638396102000100910000d9d9d9ff00000000ffffffff21f90401000000002c00000000020001000002028c0a003b
Errors
% image create photo d3 -width 2 -height 2; d3 data -from 0 0 5 5
coordinates for -from option extend outside image
-errorcode NONE
% image create photo d4; d4 data -format bmp
image string format "bmp" is unknown
-errorcode NONE
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.10