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 for PNG and GIF images). 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 -data and -file, the -file option wins, it takes precedence ๐Ÿ’….
  • -format {format-name ?option value ...?} โ€” specifies the name of the file format for the data you gave with the -data or -file option, 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 โ€” name gives 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 around 2.) The value you specify must be greater than zero. The default value is 1 (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 of 0 (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 -file or -data option and the driver outputs any metadata keys. See the section METADATA DICTIONARY below, 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 of 0 (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 the image create photo command โœจ.
  • 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 (see Tk_ConfigureInfo for 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 the image create photo command. Note that setting the -metadata option 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. If x2 and y2 aren'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 -from isn'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. If x2 and y2 aren't specified, the default value is (x1,y1) plus the size of the source region (after subsampling and zooming, if specified). If x2 and y2 are 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 -width or -height configuration option, respectively ๐Ÿ™…โ™€๏ธ.
    • -zoom x y โ€” specifies that the source region should be magnified by a factor of x in the X direction and y in the Y direction. If y isn't given, the default value is the same as x. With this option, each pixel in the source image gets expanded into a block of x x y pixels in the destination image, all the same color ๐ŸŸช๐ŸŸช๐ŸŸช. x and y must be greater than 0.
    • -subsample x y โ€” specifies that the source image should be reduced in size by using only every xth pixel in the X direction and yth pixel in the Y direction. Negative values will cause the image to be flipped about the Y or X axes, respectively ๐Ÿ”„. If y isn't given, the default value is the same as x.

  • -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 #rrggbb format (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 of imageName to return. Give only x1 and y1 and the region stretches from (x1,y1) all the way to the bottom-right corner of imageName. Give all four and they're diagonally opposite corners of the rectangle โ€” including x1,y1 and excluding x2,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 -metadata option, 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 in data is 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 of imageName where the image data gets copied. Default position is (0,0). If you give x2,y2 and data isn'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 โ€” if data is 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 only x1 and y1 and 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 of imageName gets reduced if necessary, so that the region where the image file data got read sits at the bottom-right corner of imageName. This option will not affect the width or height of the image if the user has specified a non-zero value for the -width or -height configuration option, respectively. ๐Ÿซถ
  • -to x y โ€” coordinates of the top-left corner of the region of imageName where 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 -alpha option and it returns the alpha value of the pixel instead, as an integer in the range 0 to 255. ๐Ÿ”
  • 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 -alpha option and newVal is interpreted as an integral alpha value for the pixel, which must be in the range 0 to 255. 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 the data version, bestie.
  • -format {format-name ?option value ...?} โ€” bestie, this is how you tell photo which 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 of format-name and 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 of imageName to write into the image file ๐ŸŽ€. If you only give x1 and y1, the region stretches from (x1,y1) all the way to the bottom-right corner of imageName. 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 -metadata option, 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 with imageName data. it specifies the format to use for the color string of each pixel. formatType may be one of: rgb to encode pixel data in the form #RRGGBB, rgba to encode pixel data in the form #RRGGBBAA, or list to encode pixel data as a list with four elements. see COLOR FORMATS below for details. the default is rgb. ๐Ÿ’–
  • 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 -index sub-option, the indexValue'th value may be used instead. the indexValue must be an integer from 0 up 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. the alphaValue must be between 0.0 and 1.0. ๐Ÿฆ‹
  • svg -dpi dpiValue -scale scaleValue -scaletowidth width -scaletoheight height โ€” okay this one has a lot going on, let's break it down:
    • dpiValue is used in conversion between given coordinates and screen resolution. the value must be greater than 0 and the default value is 96.
    • scaleValue is used to scale the resulting image. the value must be greater than 0 and the default value is 1.
    • width and height are the width or height that the image will be adjusted to.
    • only one parameter among -scale, -scaletowidth and -scaletoheight can be given at a time, and the aspect ratio of the original image is always preserved (no stretched-out nonsense here ๐Ÿšซ).
    • the svg format 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 value A must be a fractional value in the range 0.0 (fully transparent) to 1.0 (fully opaque).
    • #X โ€” the alpha value X is a hexadecimal digit that specifies an integer alpha value in the range 0 (fully transparent) to 255 (fully opaque). this is expanded in range from 4 bits wide to 8 bits wide by multiplication by 0x11. (math queen behaviour, we respect it ๐Ÿงฎ)
    • #XX โ€” the alpha value XX is passed as two hexadecimal digits that specify an integer alpha value in the range 0 (fully transparent) to 255 (fully opaque).
  • a Tcl list with three or four integers in the range 0 to 255, specifying the values for the red, green, blue and (optionally) alpha channels respectively.
  • #RGBA format: 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 by 0x11.
  • #RRGGBBAA format: # 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 format png. ๐Ÿ“
  • aspect โ€” Aspect ratio horizontal divided by vertical as double value. Supported by formats gif and png. ๐Ÿ“
  • comment โ€” Image text comment. Supported by formats gif and png. ๐Ÿ’ฌ

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 time time โ€” Update delay time in 10ms units. This key is only present if the delay time is not 0. โฑ๏ธ
  • disposal method method โ€” 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 interaction bool โ€” The key is present with a value of 1, if user interaction is specified. Otherwise, the key is not present. ๐Ÿ‘†
  • update region X0, 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms