ztk::photo
Resizes, crops, turns, and mirrors a photo, and reads the EXIF orientation of an image file.
Synopsis
ztk::photo resize SRC DST WIDTH HEIGHT ?-filter smooth|nearest?
ztk::photo crop SRC DST X1 Y1 X2 Y2
ztk::photo rotate SRC DST DEGREES ?-background COLOR?
ztk::photo flip SRC DST horizontal|vertical
ztk::photo orientation DATA
ztk::photo orient SRC DST ORIENTATION
Arguments
| Name | Type | Default | Description |
|---|---|---|---|
SRC |
photo | The photo to read. | |
DST |
photo | The photo that gets the result, with its size, -width and -height 0, and the -density of SRC. DST can be SRC. |
|
WIDTH, HEIGHT |
integer | The new size. A 0 for one side keeps the aspect ratio. The largest side is 8,192. | |
-filter |
smooth or nearest |
smooth |
smooth averages the area under each new pixel along a side that gets smaller and blends the 2 nearest pixels along a side that gets larger. nearest uses the pixel under the middle of each new pixel. |
X1 Y1 X2 Y2 |
integers | The region, the end not counted, inside SRC. | |
DEGREES |
number | The turn, anticlockwise on the screen, as canvas rotate. A multiple of 90 moves the pixels exactly; another angle gives a box that holds the whole turned image. |
|
-background |
color | clear | The color of the corners of a turn by another angle. |
DATA |
bytes | The bytes of a JPEG or PNG file. | |
ORIENTATION |
integer | An EXIF orientation from 1 to 8, as orientation gives it. |
The photo command of Tk has none of these, so they are a command of their own. The code is ztk's own, so each platform gives the same pixels. A blend of pixels works on the colors times their alpha, so a clear pixel gives no dark edge. A photo that reads a file leaves its orientation alone, as in Tk: orient turns it upright.
Return value
orientation gives an integer from 1 to 8: the TIFF tag 274 of the Exif segment of a JPEG or of the chunk eXIf of a PNG, or 1 when there is none. The other subcommands give an empty string.
Errors
| Error | When |
|---|---|
image "NAME" doesn't exist or is not a photo image |
SRC or DST is no photo. |
unknown or ambiguous subcommand "X": must be crop, flip, orient, orientation, resize, or rotate |
The subcommand is unknown. |
bad size "W H": the width and the height must be 0 or more, and one more than 0 |
resize with a negative side, or two sides of 0. |
the region X1 Y1 X2 Y2 is outside the image of W by H |
crop with a region past the edge of SRC. |
bad direction "X": must be horizontal or vertical |
flip with another word. |
bad orientation "X": must be 1 to 8 |
orient with another number. |
wrong # args: should be "ztk::photo SUBCOMMAND ..." |
The count of arguments is wrong. |
Platforms
| Platform | Works |
|---|---|
| Windows | Yes |
| macOS | Yes |
| Linux, Wayland | Yes |
| Linux, X11 | Yes |
| Web | Yes |
| iOS, Android | Yes |
| Headless | Yes |
Example
image create photo big -width 400 -height 300
big put #3366cc -to 0 0 400 300
image create photo thumb
ztk::photo resize big thumb 100 0
ztk::photo rotate thumb thumb 90
list [image width thumb] [image height thumb]