photo(n)
photo(n) โ Tk Built-In Commands
okay bestie, sit DOWN, because this is the full-color image page and it's lowkey iconic ๐ โจ
๐ธ NAME ๐ธ
photo โ full-color images. every color. every vibe. plus transparency, so it's giving stained glass but make it pixels ๐ฆ
โจ SYNOPSIS โจ
image create photo ?name? ?options?
imageName blank
imageName cget option
imageName configure ?option? ?value option value ...?
imageName copy sourceImage ?option value(s) ...?
imageName data ?option value(s) ...?
imageName get x y ?option?
imageName put data ?option value(s) ...?
imageName read filename ?option value(s) ...?
imageName redither
imageName transparency subcommand ?arg ...?
imageName write filename ?option value(s) ...?
๐ DESCRIPTION ๐
So a photo is an image whose pixels can display any color with a varying degree of transparency โ that's the alpha channel, bestie, the thing that makes your PNGs not have crusty white boxes around them ๐ซถ. A photo image is stored internally in full color (32 bits per pixel), and it gets displayed using dithering if necessary.
You can get image data for a photo image from a file or a string, or you can hand it over from C code through a procedural interface. Right now? Only PNG, GIF, PPM/PGM, and (read-only ๐) SVG formats are supported โ but there's an interface that lets additional image file formats get added easily, so the roster can grow, no cap.
A photo image is (semi)transparent if the image data it was obtained from had transparency information. And in regions where no image data has been supplied at all? fully transparent, periodt โ the window behind it just shows right on through. You can also change transparency with the transparency set subcommand. ๐
๐ CREATING PHOTOS ๐
Like all images, photos are created using the image create command. Photos support the following options:
-data stringโ specifies the contents of the image as a string ๐. That string should contain data in the default list-of-lists form, binary data, or โ for some formats โ base64-encoded data (and rn that's currently guaranteed to be supported forPNGandGIFimages). The format of the string has to be one of those for which there's an image file format handler that will accept string data. And heads up: if you specify both-dataand-file, the-fileoption wins, it takes precedence ๐ .-format {format-name ?option value ...?}โ specifies the name of the file format for the data you gave with the-dataor-fileoption, plus optional arguments passed to the format handler. Ngl, the value of this option must be a Tcl list โ which means the braces can be omitted if the argument has only one word. Also, instead of braces you can use double quotes for quoting โจ.-file nameโnamegives the name of a file that's gonna be read to supply data for the photo image. The file format has to be one of those for which there's an image file format handler that can read data ๐๏ธ.-gamma valueโ says that the colors allocated for displaying this image in a window should be corrected for a non-linear display using the specified gamma exponent value. (The intensity produced by most CRT displays is a power function of the input value, to a good approximation; gamma is the exponent and is typically around2.) The value you specify must be greater than zero. The default value is1(no correction). In general, values greater than one make the image lighter and values less than one make it darker ๐.-height numberโ specifies the height of the image, in pixels ๐. This option is useful primarily when the user wants to build up the contents of the image piece by piece. A value of0(the default) lets the image expand or shrink vertically to fit the data stored in it.-metadata metadataโ sets the metadata dictionary of the image ๐ท๏ธ. Additional keys may be set within the metadata dictionary of the image if image data is processed due to a-fileor-dataoption and the driver outputs any metadata keys. See the sectionMETADATA DICTIONARYbelow, bestie, we'll get there ๐.-palette palette-specโ specifies the resolution of the color cube to be allocated for displaying this image, and therefore the number of colors used from the colormaps of the windows where it's displayed ๐จ. The palette-spec string can be either a single decimal number, specifying the number of shades of gray to use, or three decimal numbers separated by slashes (/), specifying the number of shades of red, green and blue to use, respectively. If you use the first form (a single number), the image will be displayed in monochrome (i.e., grayscale).-width numberโ specifies the width of the image, in pixels ๐. This option is useful primarily when the user wants to build up the contents of the image piece by piece. A value of0(the default) lets the image expand or shrink horizontally to fit the data stored in it.
๐ฆ IMAGE COMMAND ๐ฆ
When a photo image is created, Tk also creates a new command whose name is the same as the image ๐. This command is how you invoke various operations on the image. Its general form is:
imageName option ?arg ...?
Option and the args decide exactly what the command does, fr fr.
Okay here's a thing to remember: those options that write data to the image generally expand the size of the image if necessary, so the data written fits โ unless the user 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. Protect those dimensions, bestie ๐ก๏ธ.
The following commands are possible for photo images:
imageName blankโ blanks the image; that is, sets the entire image to have no data, so it displays as transparent and the background of whatever window it's displayed in shows through. The metadata dict of the image is not changed ๐.imageName cget optionโ returns the current value of the configuration option given by option. Option may have any of the values accepted by theimage create photocommand โจ.imageName configure ?option? ?value option value ...?โ query or modify the configuration options for the image. If no option is specified, it returns a list describing all of the available options for imageName (seeTk_ConfigureInfofor info on the format of this list). If option is specified with no value, then the command returns a list describing that one named option (this list will be identical to the corresponding sublist of the value returned when no option is specified). If one or more option-value pairs are specified, then the command modifies the given option(s) to have the given value(s) โ and in that case the command returns an empty string. Option may have any of the values accepted by theimage create photocommand. Note that setting the-metadataoption without any other option will not invoke the image format driver to recreate the bitmap ๐.imageName copy sourceImage ?option value(s) ...?โ copies a region from the image called sourceImage (which must be a photo image) to the image called imageName, possibly with pixel zooming and/or subsampling ๐. If no options are specified, this command copies the whole of sourceImage into imageName, starting at coordinates(0,0)in imageName. The following options may be specified:-from x1 y1 x2 y2โ specifies a rectangular sub-region of the source image to be copied.(x1,y1)and(x2,y2)specify diagonally opposite corners of the rectangle. Ifx2andy2aren't specified, the default value is the bottom-right corner of the source image. The pixels copied will include the left and top edges of the specified rectangle but not the bottom or right edges. If-fromisn't given, the default is the whole source image.-to x1 y1 x2 y2โ specifies a rectangular sub-region of the destination image to be affected.(x1,y1)and(x2,y2)specify diagonally opposite corners of the rectangle. Ifx2andy2aren't specified, the default value is(x1,y1)plus the size of the source region (after subsampling and zooming, if specified). Ifx2andy2are specified, the source region will be replicated if necessary to fill the destination region in a tiled fashion ๐งฉ.-shrinkโ specifies that the size of the destination image should be reduced, if necessary, so that the region being copied into is at the bottom-right corner of the image. This option will not affect the width or height of the image if the user specified a non-zero value for the-widthor-heightconfiguration option, respectively ๐ โ๏ธ.-zoom x yโ specifies that the source region should be magnified by a factor ofxin the X direction andyin the Y direction. Ifyisn't given, the default value is the same asx. With this option, each pixel in the source image gets expanded into a block ofxxypixels in the destination image, all the same color ๐ช๐ช๐ช.xandymust be greater than0.-subsample x yโ specifies that the source image should be reduced in size by using only everyxth pixel in the X direction andyth pixel in the Y direction. Negative values will cause the image to be flipped about the Y or X axes, respectively ๐. Ifyisn't given, the default value is the same asx.
-compositingrule ruleโ tells the command how transparent pixels in the source image get smushed together with the destination image. Two moods:overlayโ the old contents of the destination stay visible, like the source image got printed on a sheet of transparent film and laid over the top of the destination. โจsetโ the old contents of the destination get yeeted, and the source image is used exactly as-is. ๐
Default vibe is overlay.
๐ธ imageName data ?option value(s) ...? ๐ธ
Hands you the image data back as a string. The format of that string is fully up to the format handler. By default you get a human-readable format โ a list of lists of pixel data โ but you can pick something else with -format. Check IMAGE FORMATS below for the deets. Options you can throw at it:
-background colorโ if you give a color, the data will not carry any transparency info. Every transparent pixel gets replaced with the color you named. bye opacity ๐-format {format-name ?option value ...?}โ names the image file format handler to use, plus optionally some arguments for that handler. Specifically, this subcommand hunts for the first handler whose name matches an initial substring of format-name and that can actually write a string containing this image data. If you skip this option, it uses the default format: a list (one element per row) of lists (one element per pixel/column) of colors in#rrggbbformat (see IMAGE FORMATS below). Heads up โ the value of this option must be a Tcl list. Which means the braces can be left out if the argument is just one word. Also, double quotes work for quoting instead of braces. iykyk ๐-from x1 y1 x2 y2โ picks a rectangular region ofimageNameto return. Give onlyx1andy1and the region stretches from(x1,y1)all the way to the bottom-right corner ofimageName. Give all four and they're diagonally opposite corners of the rectangle โ includingx1,y1and excludingx2,y2. Default if you don't say anything is the whole image. the whole thing, no crumbs. ๐-grayscaleโ with this on, the data won't carry any color info. All pixel data gets transformed into grayscale. monochrome era.-metadata metadataโ the image format handler may use metadata that gets included in the returned data string. The metadata you specify is passed to the driver to be included in the data. If you don't give a-metadataoption, the image's current metadata is used.
๐ฆ imageName get x y ?-withalpha? ๐ฆ
Returns the color of the pixel at coordinates (x,y) as a list of three integers between 0 and 255, standing for the red, green and blue components respectively. Add the -withalpha option and the returned list gets a fourth element โ the alpha value of that pixel, an integer between 0 and 255. four numbers, zero mystery.
๐ฅ imageName put data ?option value(s) ...? ๐ฅ
Sets pixels in imageName to the data you hand over in data. This command goes through the list of image file format handlers looking for one that can interpret the data in data, then reads the image encoded inside it into imageName (that's the destination image, bestie). See IMAGE FORMATS below for the whole tea on image data formats. Options available:
-format {format-name ?option value ..?}โ says what format the image data indatais in, plus optionally arguments to pass along to the format handler. Specifically, only image file format handlers whose names begin with format-name get used while it searches for an image data format handler to read the data. Note that the value of this option must be a Tcl list. So the braces can be dropped if the argument is a single word, and double quotes can quote instead of braces. ๐-metadata metadataโ the metadata you specify gets passed to the image format driver when it interprets the data. Important: the image's current metadata is not passed to the format driver, and it is not changed by the command. no sneaky side effects.-to x1 y1 ?x2 y2?โ the coordinates of the top-left corner(x1,y1)of the region ofimageNamewhere the image data gets copied. Default position is(0,0). If you givex2,y2anddataisn't big enough to cover the rectangle from this option, the extracted image data gets tiled so it covers the whole destination rectangle. If the region from this option is smaller than the data you supplied, the extra data is silently discarded. ๐ And note โ ifdatais just a single color value, then a region stretching to the bottom-right corner, represented by(x2,y2), gets filled with that color. fill mode unlocked.
๐ง imageName read filename ?option value(s) ...? ๐ง
Reads image data from the file named filename into the image. First it searches the list of image file format handlers for one that can interpret the data in filename, then reads the image in filename into imageName (the destination image). Options:
-format {format-name ?option value ..?}โ says the format of the image data in filename, plus optionally extra options for the format handler. Specifically, only image file format handlers whose names begin with format-name get used while searching for an image data format handler to read the data. Note that the value of this option must be a Tcl list โ so braces can be omitted for a single-word argument, and double quotes work for quoting too. ๐-from x1 y1 x2 y2โ a rectangular sub-region of the image file data to copy into the destination image. Give onlyx1andy1and the region stretches from(x1,y1)to the bottom-right corner of the image in the image file. Give all four and they're diagonally opposite corners of the region. Default when this option isn't specified is the whole image in the image file. cropping, but make it iconic.-metadata metadataโ the metadata you specify gets passed to the image format driver when it interprets the data. Note that the image's current metadata is not passed to the format driver and is not changed by the command.-shrinkโ with this option, the size ofimageNamegets reduced if necessary, so that the region where the image file data got read sits at the bottom-right corner ofimageName. This option will not affect the width or height of the image if the user has specified a non-zero value for the-widthor-heightconfiguration option, respectively. ๐ซถ-to x yโ coordinates of the top-left corner of the region ofimageNamewhere the data from filename gets read into. Default is(0,0).
โญ imageName redither โญ
The dithering algorithm used to display photo images propagates quantization errors from one pixel to its neighbors. So if the image data for imageName arrives in pieces, the dithered image might not be exactly correct. Usually the difference is invisible, but if it is a problem, this command recalculates the dithered image in every window where the image is displayed. fixing the pixels' gossip chain.
๐ imageName transparency subcommand ?arg ...? ๐
Lets you look at and mess with the transparency info in the photo image. Several subcommands are available:
imageName transparency get x y ?-alpha?โ returns true if the pixel at(x,y)is fully transparent, false otherwise. Pass the-alphaoption and it returns the alpha value of the pixel instead, as an integer in the range0to255. ๐imageName transparency set x y newVal ?-alpha?โ changes the transparency of the pixel at(x,y)to newVal. If you don't pass an additional option, newVal is interpreted as a boolean: the pixel becomes fully transparent if that value is true, fully opaque otherwise. Pass the-alphaoption and newVal is interpreted as an integral alpha value for the pixel, which must be in the range0to255. out of range is a no.
๐ imageName write filename ?option value(s) ...? ๐
Writes image data from imageName out to a file named filename. Options:
-background colorโ if you give a color, the data won't contain any transparency information. Every transparent pixel gets replaced with the color you named. same energy as thedataversion, bestie.-format {format-name ?option value ...?}โ bestie, this is how you tellphotowhich image file format handler is gonna write your data to the file, plus any extra options you wanna hand off to that handler. Lowkey genius how it picks: it hunts for the first handler whose name matches an initial substring offormat-nameand that actually has the capability to write an image file. No-format? Then it just guesses the format from the file extension ๐ต๏ธ. And if even that can't be figured out, it falls back to the first handler that can write an image file. Periodt.
Heads up bestie: the value of this option must be a Tcl list. Which means you can skip the braces entirely if the argument is just one word โจ. And instead of braces, double quotes work fine for quoting too. iykyk.
-from x1 y1 x2 y2โ ok so this one lets you carve out just a rectangular region ofimageNameto write into the image file ๐. If you only givex1andy1, the region stretches from(x1,y1)all the way to the bottom-right corner ofimageName. Give all four coordinates and they define diagonally opposite corners of the rectangle. Don't give this option at all? Default is the whole entire image, no cap ๐.-grayscaleโ say it with me: no color ๐ . If you pass this, the data will not contain color information, and all pixel data gets transformed into grayscale. It's giving moody film-still energy fr fr ๐ฆ.-metadata metadataโ the image format handler may use metadata to be included in the written file, and this is where you feed it. Whatever metadata you specify gets passed to the driver for inclusion in the file ๐. If you don't give a-metadataoption, then the current metadata of the image is what gets used. Iconic, honestly ๐.
IMAGE FORMATS ๐
okay so bestie, the photo image code? it's built super modular on purpose. like, the whole thing is structured so that handlers for extra image file formats can be added so easily, and the photo image code keeps a lil list of all of them. handlers get added to that list by registering them with a call to Tk_CreatePhotoImageFormat. the standard Tk distribution ships with handlers for PPM/PGM, PNG, GIF and (read-only, so no writing, bestie ๐ญ) SVG formats, plus the default handler that encodes/decodes image data in a human readable form. and the way these handlers are automatically registered on initialization? iconic. no setup required, they just show up. โจ
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 finds the correct handler, but if it doesn't? the user may give a format name with the -format option to specify which handler to use. in that case, the photo image code will try those handlers whose names begin with the string specified for the -format option (and the comparison is case-insensitive, we love an inclusive queen ๐
). 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. so if ur transparency is ghosting you, that might be why ๐
THE DEFAULT IMAGE HANDLER ๐
the default image handler cannot be used to read or write data from/to a file. its sole purpose? encode and decode image data in string form, in a clear text, human readable form. that's it. that's the whole job. its imageName data subcommand uses this handler when no other format is specified. and when reading image data from a string with imageName put or the -data option, the default handler is treated just like the other handlers. no special treatment, it's giving humble. ๐
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. ๐
FORMAT SUBOPTIONS โจ
image formats may support sub-options, which are specified using additional words in the value to the -format option. these suboptions can affect how image data is read or written to file or string. the nature and values of these options is up to the format handler (its little kingdom, its rules ๐). the built-in handlers support these suboptions:
default -colorformat formatTypeโ this option is allowed when writing image data to a string withimageName data. it specifies the format to use for the color string of each pixel.formatTypemay be one of:rgbto encode pixel data in the form#RRGGBB,rgbato encode pixel data in the form#RRGGBBAA, orlistto encode pixel data as a list with four elements. see COLOR FORMATS below for details. the default isrgb. ๐gif -index indexValueโ this option has effect when reading image data from a file. when parsing a multi-part GIF image, Tk normally only accesses the first image. but by giving the-indexsub-option, theindexValue'th value may be used instead. theindexValuemust be an integer from0up to the number of image parts in the GIF data. so if u wanted the second frame, that's index 1, bestie. ๐ธpng -alpha alphaValueโ this option has effect when reading image data from a file. it specifies an additional alpha filtering for the overall image, which allows the background on which the image is displayed to show through. this usually also has the effect of desaturating the image. thealphaValuemust be between0.0and1.0. ๐ฆsvg -dpi dpiValue -scale scaleValue -scaletowidth width -scaletoheight heightโ okay this one has a lot going on, let's break it down:dpiValueis used in conversion between given coordinates and screen resolution. the value must be greater than0and the default value is96.scaleValueis used to scale the resulting image. the value must be greater than0and the default value is1.widthandheightare the width or height that the image will be adjusted to.- only one parameter among
-scale,-scaletowidthand-scaletoheightcan be given at a time, and the aspect ratio of the original image is always preserved (no stretched-out nonsense here ๐ซ). - the
svgformat supports a wide range of SVG features, but the full SVG standard is not available โ for instance the'text'feature is missing and silently ignored when reading the SVG data. (silently?! okay girl we see u ๐)
the supported SVG features are:
elements: g, path, rect, circle, ellipse, line, polyline, polygon, linearGradient, radialGradient, stop, defs, svg, style
attributes: width, height, viewBox, preserveAspectRatio with none, xMin, xMid, xMax, yMin, yMid, yMax, slice
gradient attributes: gradientUnits with objectBoundingBox, gradientTransform, cx, cy, r fx, fy x1, y1, x2, y2 spreadMethod with pad, reflect or repeat, xlink:href
poly attributes: points
line attributes: x1, y1, x2, y2
ellipse attributes: cx, cy, rx, ry
circle attributes: cx, cy, r
rectangle attributes: x, y, width, height, rx, ry
path attributes: d with m, M, l, L, h, H, v, V, c, C, s, S, q, Q, t, T, a, A, z, Z
style attributes: display with none, visibility, hidden, visible, fill with nonzero and evenodd, opacity, fill-opacity, stroke, stroke-width, stroke-dasharray, stroke-dashoffset, stroke-opacity, stroke-linecap with butt, round and square, stroke-linejoin with miter, round and bevel, stroke-miterlimit fill-rule, font-size, transform with matrix, translate, scale, rotate, skewX and skewY, stop-color, stop-opacity, offset, id, class
currently only SVG images reading and conversion into (pixel-based format) photos is supported: Tk does not (yet) support bundling photo images in SVG vector graphics. so no, u cannot make ur vector graphics a photo and have it stay vector. one day maybe bestie, one day ๐
COLOR FORMATS ๐
the default image handler can represent/parse color and alpha values of a pixel in one of the formats listed below. if a color format does not contain transparency information, full opacity is assumed. the available color formats are:
- the empty string โ interpreted as full transparency, and the color value is undefined. so nothing = see-through, got it. ๐
- any value accepted by
Tk_GetColor, optionally followed by an alpha suffix. the alpha suffix may be one of:@Aโ the alpha valueAmust be a fractional value in the range0.0(fully transparent) to1.0(fully opaque).#Xโ the alpha valueXis a hexadecimal digit that specifies an integer alpha value in the range0(fully transparent) to255(fully opaque). this is expanded in range from 4 bits wide to 8 bits wide by multiplication by0x11. (math queen behaviour, we respect it ๐งฎ)#XXโ the alpha valueXXis passed as two hexadecimal digits that specify an integer alpha value in the range0(fully transparent) to255(fully opaque).
- a Tcl list with three or four integers in the range
0to255, specifying the values for the red, green, blue and (optionally) alpha channels respectively. #RGBAformat: a#followed by four hexadecimal digits, where each digit is the value for the red, green, blue and alpha channels respectively. each digit will be expanded internally to 8 bits by multiplication by0x11.#RRGGBBAAformat:#followed by eight hexadecimal digits, where each pair of subsequent digits represents the value for the red, green, blue and alpha channels respectively. the full glow-up version of a color spec, honestly. โจ
๐ COLOR ALLOCATION ๐
Okay bestie, so when a photo image gets displayed in a window, the photo image code has to actually allocate colors to show it off โ and if the vibes (read: available colors) aren't quite right, it dithers the image to give you a reasonable approximation using whatever colors it managed to get. ๐
The colors get allocated as a color cube, meaning the number of colors allocated is the product of the number of shades of red, green and blue. Math girl summer fr fr.
Normally, the number of colors allocated is chosen based on the depth of the window. Like:
- 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. Not me being shook at the efficiency. ๐ญ
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. Persistence!! ๐
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. Slay, monochrome era. ๐ค๐ค
๐ METADATA DICTIONARY ๐
Each image has a metadata dictionary property. This dictionary is not relevant to the bitmap representation of the image, but it may contain additional information like resolution or comments. Image format drivers may output metadata when image data is parsed, or may use metadata to be included in image files or formats. It's giving side-quest information, and honestly? We love her. ๐ซถ
โจ METADATA KEYS (MULTIPLE FORMATS) โจ
Each image format driver supports an individual set of metadata dictionary keys. The predefined keys are:
DPIโ Horizontal image resolution in DPI as a double value. Supported by formatpng. ๐aspectโ Aspect ratio horizontal divided by vertical as double value. Supported by formatsgifandpng. ๐commentโ Image text comment. Supported by formatsgifandpng. ๐ฌ
It is valid to set any key in the metadata dict. A format driver will ignore keys that it does not handle. No drama, it just moves on. ๐
๐ฆ METADATA KEYS FOR ANIMATED GIF INFORMATION ๐ฆ
The following metadata keys are reported when reading a gif format file. They are typically used in conjunction with the -index option of an animated gif file to properly display the subimage sequence. The options are linked to each subimage selected by -index. It's giving "every frame has lore." ๐๏ธ
delay timetime โ Update delay time in 10ms units. This key is only present if the delay time is not 0. โฑ๏ธdisposal methodmethod โ Disposal method of the preceeding image, if given for the current image. Possible values are: do not dispose, restore to background color, restore to previous. ๐๏ธuser interactionbool โ The key is present with a value of 1, if user interaction is specified. Otherwise, the key is not present. ๐update regionX0, Y0, width, height โ Update region of the current subimage, if subimage has not the same size as the full image. The pixel outside of this box are all fully transparent. ๐ซฅ
๐ CREDITS ๐
The photo image type was designed and implemented by Paul Mackerras, based on his earlier photo widget and some suggestions from John Ousterhout. Legends only, we thank them for their service. ๐ซก๐
๐ฅ EXAMPLE ๐ฅ
Load an image from a file and tile it to the size of a window, which is useful for producing a tiled background:
# 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
๐ SEE ALSO ๐
image(n)โ go read her next, bestie, she's the moment. โจ
๐ธ KEYWORDS ๐ธ
photo, image, color โ the whole trio, iconic, no notes. ๐
And that's a wrap on photo(n), bestie!! ๐ This page is from Tk 4.0, and the date stamp lives right down there in the footer next to it โ go check her out, she's been holding it down since forever. Stay allocated, stay dithered, stay slaying. ๐โจ๐ฆ
๐ฆ where this page comes from
- fedora 43: tk 1:9.0.2-2.fc43 ยท TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 43: tk 1:9.0.2-2.fc43 ยท TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk 1:9.0.2-2.fc44 ยท TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk 1:9.0.2-2.fc44 ยท TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- Copyright (c) 1994 The Australian National University
- Copyright (c) 1994-1997 Sun Microsystems, Inc
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms