Image(3pm)
π Tk::Image β Create and manipulate images π
okay bestie, sit down, we're doing images today. this is Tk::Image, and it's literally the whole vibe of making, yeeting, and interrogating images in Perl/Tk. π
β¨ SYNOPSIS β¨
$image = $widget->type(?arg arg ...?)
$image->method(?arg arg ...?)
π¦ DESCRIPTION π¦
So the image constructors and methods are your little toolkit for creating, deleting, and querying images. it can take a few different forms depending on the type, iykyk. π
The constructors need a $widget to invoke them β that's how they find a MainWindow. (why, you ask? because the underlying Tk code registers the images in the data structure for the MainWindow. that's the whole reason. no cap.)
The legal forms are:
$widget->type?(?name?,?option=>value ...)?β creates a new image and hands you back an object.typesays what kind of image it is, and it has to be one of the types currently defined (like, say,Bitmap).nameis the name for the image; if you skip it, Tk just picks a name of the formimagex, wherexis an integer. you can throw in any number ofoption=>valuepairs to configure your shiny new image. the legal set of options is defined separately for each image type β scroll down for the deets on the built-in ones. and heads up: if an image already exists with the name you gave, it gets replaced with the new image, and every instance of that image will redisplay with the new contents. glow-up, immediately. β¨$image->deleteβ deletes the image$imageand returns an empty string. but okay, plot twist: if there are instances of the image currently displayed in widgets, the image won't actually be deleted until all those instances are released. the association between the instances and the image manager does get dropped though. existing instances keep their sizes but redisplay as empty areas. and if a deleted image gets recreated (same name!), the existing instances will use the new image. iconic behavior honestly.$image->heightβ returns a decimal string giving the height of image name in pixels. π$image->inuseβ returns a boolean value telling you whether or not the image is in use by any widgets.$widget->imageNamesβ returns a list containing all existing images for$widget's MainWindow.$image->typeβ returns the type of$image(aka the value of the type method back when the image was created).$widget->imageTypesβ returns a list whose elements are all of the valid image types (i.e., every value you could possibly supply for the type when creating an image).$image->widthβ returns a decimal string giving the width of image name in pixels. π
π BUILT-IN IMAGE TYPES π
These are the image types Tk defines, so they're available in any Tk application, fr fr. individual applications or extensions may define additional types on top of these.
- Bitmap β every pixel in the image displays a foreground color, a background color, or nothing at all. see
Tk::Bitmapfor more info. - Pixmap β slightly more general than Bitmap: each pixel can be any available color, or
"transparent"(which renders as the background color of the widget the image is displayed in). Pixmap is best for icons and other simple graphics with only a few colors. Pixmap is derived from Tix. seeTk::Pixmapfor more info. - Photo β displays a whole variety of full-color images, using dithering to approximate colors on displays with limited color capabilities. see the
Tk::Photodocumentation for more info. πΈ
π CAVEATS π
bestie this one is IMPORTANT. you have to use the"delete"method to delete an image object and free the memory associated with it. just storing the image object in a lexical variable and letting that variable go out of scope β or setting it to"undef"β is not sufficient. the memory will not free itself. it's giving leaks. π
π«Ά SEE ALSO π«Ά
Tk::Bitmap Tk::Pixmap Tk::Photo
π KEYWORDS π
height, image, types of images, width
and that's the whole page, bestie!! π this was brought to you by perl v5.40.1, dated 2025-04-13 β Image(3pm) said it, slay, periodt. πβ¨
π¦ where this page comes from
- debian trixie: perl-tk 1:804.036+dfsg1-5
- ubuntu questing: perl-tk 1:804.036+dfsg1-5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms