pix 0.7: Reference Manual

::pix::imgTop, Main, Index

CommandsTop, Main, Index

applyOpacity [::pix::img]Top, Main, Index

Multiplies alpha of the image by opacity.

applyOpacity image opacity
Parameters
imageimg::new
opacitydouble value
Description

Image pix::img::applyOpacity multiplies the opacity of the image by the opacity parameter. The opacity parameter is a double between 0 and 1. 0 is fully transparent. 1 is fully opaque.
Any value inbetween is a mix of the two.

Return value

Nothing.

blur [::pix::img]Top, Main, Index

Applies Gaussian blur to the image given a radius.

blur image radius ?color?
Parameters
imageimg::new
radiusdouble value
colorstring color Optional, default transparent.
Return value

Nothing.

ceil [::pix::img]Top, Main, Index

A value of 0 stays 0. Anything else turns into 255.

ceil image
Parameters
imageimg::new
Description

The pix::img::ceil proc takes an image and replaces all pixels that are not fully transparent (i.e. have an alpha of 0) with a pixel that is fully opaque (i.e. has an alpha of 255). This is useful for creating masks from images.

Return value

Nothing.

copy [::pix::img]Top, Main, Index

This procedure creates a new image by copying the contents of the given image object.

copy image
Parameters
imageimg::new
Return value

A new img object.

destroy [::pix::img]Top, Main, Index

Destroy current image or all images if special word all is specified.

destroy value
Parameters
valueimg::new object or string
Return value

Nothing.

diff [::pix::img]Top, Main, Index

Call this proc on the master image, passing the image to compare to the master image. The pix::img::diff method returns a dict with two elements.

diff masterimage image
Parameters
masterimageimg::new
imageimg::new
Description

1. A cdouble representing the difference score between the two images. This score is 0 if the images are identical, and 1 if the images are completely different. The score is a measure of how different the two images are.

2. A new pix image representing the difference between the two images. The difference image is an image that has the same size as the two input images, and the pixels in this image represent the difference between the corresponding pixels in the two images. The difference image will have the same format as the input images.

Return value

A Tcl dictionary with keys (score, imgdiff).

draw [::pix::img]Top, Main, Index

Draws one image onto another using a matrix transform and color blending.

draw image image2 ?matrix3? ?blendMode?
Parameters
imageimg::new
image2img::new
matrix3list Optional, default mat3.
blendModeEnum value Optional, default NormalBlend.
Return value

Nothing.

fill [::pix::img]Top, Main, Index

Fills the image with the color.

fill image value
Parameters
imageimg::new
valuestring color or paint object
Description

This proc takes an image object and a color or paint object as arguments. It will fill the image with the specified color or paint object. The color or paint object can be specified as a string or as an object. If a string is specified, it should be a valid color string. If a paint object is specified, it should be a valid paint object. The paint object can be created using the pix::paint::new proc.

Return value

Nothing.

fillGradient [::pix::img]Top, Main, Index

Fills with the Paint gradient.

fillGradient image paint
Parameters
imageimg::new
paintpaint::new
Return value

Nothing.

fillPath [::pix::img]Top, Main, Index

Fills a path with a color or paint object.

fillPath image pathValue paintValue ?matrix?
Parameters
imageThe img::new object to draw on.
pathValueA string containing a path or a path object. The path can be specified as a string like this: M 0 0 L 100 0 L 100 100 Z or as a path object created with the pix::path::new proc.
paintValueA string containing a color or a paint object. The color can be specified as a string like this: #FF0000 or as a paint object created with the pix::paint::new proc.
matrixA matrix to transform the path with. The matrix should be a 3x3 matrix specified as a list of 9 numbers. Optional, default mat3idendity.
Return value

Nothing.

fillText [::pix::img]Top, Main, Index

Fills the image with the rendered text.

fillText image object ?args?
Parameters
imageimg::new
objectfont::typeset or font::readFont object
argsA Tcl dict (options described below)
Description

There are two ways to use this proc:

1. With an font::typeset object:

2. With a font object and a text string:

In either case, the img object is the first argument, and the font::typeset or font::readFont object is the second argument.

Return value

Nothing.

flipHorizontal [::pix::img]Top, Main, Index

This method modifies the image in place, flipping it around the Y-axis. As a result, the left and right sides of the image are swapped. This operation is useful for creating mirror images or for certain graphical effects.

flipHorizontal image
Parameters
imageimg::new
Return value

Nothing.

flipVertical [::pix::img]Top, Main, Index

This method modifies the image in place, flipping it around the X-axis.

flipVertical image
Parameters
imageimg::new
Description

As a result, the top and bottom sides of the image are swapped. This operation is useful for creating mirror images or for certain graphical effects.

Return value

Nothing.

get [::pix::img]Top, Main, Index

Gets image size.

get image
Parameters
imageimg::new
Return value

A Tcl dictionary with keys containing the width and the height of the img.

getColor [::pix::img]Top, Main, Index

Gets a color at (x, y) or returns transparent black if outside of bounds.

getColor image coordinates
Parameters
imageimg::new
coordinateslist x,y
Return value

A Tcl dictionary with keys (r, g, b, a) representing the red, green, blue, and alpha (opacity) values of the pixel color.

getPixel [::pix::img]Top, Main, Index

Gets a pixel at (x, y) or returns transparent black if outside of bounds.

getPixel image coordinates
Parameters
imageimg::new
coordinateslist x,y (x column of the pixel, y row of the pixel)
Return value

A Tcl dictionary with keys (r, g, b, a) representing the red, green, blue, and alpha (opacity) values of the pixel color.

inside [::pix::img]Top, Main, Index

Returns true if (x, y) is inside the image, false otherwise.

inside image coordinates
Parameters
imageimg::new
coordinateslist x,y
Return value

Returns true if (x, y) is inside the image, false otherwise.

invert [::pix::img]Top, Main, Index

Inverts all of the colors and alpha.

invert image
Parameters
imageimg::new
Description

This will flip the image by changing the color and alpha of every pixel. The result will be a new image where every pixel is the exact opposite of the corresponding pixel in the original image.

For example, if the original image is entirely white, the resulting image will be entirely black. If the original image is entirely black, the resulting image will be entirely white. This is useful for things like getting the negative of an image, or creating a reverse version of an image.

Return value

Nothing.

isOneColor [::pix::img]Top, Main, Index

Checks if the entire image is the same color.

isOneColor image
Parameters
imageimg::new
Return value

A Tcl boolean value.

isOpaque [::pix::img]Top, Main, Index

Checks if the entire image is opaque (alpha values are all 255).

isOpaque image
Parameters
imageimg::new
Return value

A Tcl boolean value.

isTransparent [::pix::img]Top, Main, Index

Checks if this image is fully transparent or not.

isTransparent image
Parameters
imageimg::new
Return value

Returns true, false otherwise.

magnifyBy2 [::pix::img]Top, Main, Index

Scales image up by 2 ^ power.

magnifyBy2 image ?power?
Parameters
imageimg::new
powerinteger value Optional, default 1.
Description

If only one argument is given (i.e. the image object), just magnify by 2. This is a convenience for the user.

Return value

A new img object.

minifyBy2 [::pix::img]Top, Main, Index

Scales the image down by an integer scale.

minifyBy2 image ?power?
Parameters
imageimg::new
powerinteger value Optional, default 1.
Description

We were given an integer power as an argument, so we call img.minifyBy2() with that power. This will scale the image down by 2^power.

Return value

A new img object.

new [::pix::img]Top, Main, Index

Sets a new image.

new size
Parameters
sizelist width,height
Return value

A new img object.

opaqueBounds [::pix::img]Top, Main, Index

Checks the bounds of opaque pixels.

opaqueBounds image
Parameters
imageimg::new
Description

Some images have transparency around them, use this to find just the visible part of the image and then use subImage to cut it out. Returns zero rect if whole image is transparent, or just the size of the image if no edge is transparent.

Return value

Returns A Tcl dictionary with keys (x, y, w, h).

readImage [::pix::img]Top, Main, Index

Read image file.

readImage filePath
Parameters
filePathpath file
Description

This proc will attempt to read the image file and create a new image object from it.

Return value

A new img object.

resize [::pix::img]Top, Main, Index

Resize an image to a given height and width

resize image size
Parameters
imageimg::new
sizelist width,height
Return value

Nothing.

rotate90 [::pix::img]Top, Main, Index

Rotates the image 90 degrees clockwise.

rotate90 image
Parameters
imageimg::new
Return value

Nothing.

setPixel [::pix::img]Top, Main, Index

Sets a pixel at (x, y) or does nothing if outside of bounds.

setPixel image coordinates color
Parameters
imageimg::new
coordinateslist x,y
colorstring color
Return value

Nothing.

shadow [::pix::img]Top, Main, Index

Create a shadow of the image with the offset, spread and blur.

shadow image options
Parameters
imageimg::new
optionsdict (offset, spread, blur, color)
Return value

Nothing.

strokePath [::pix::img]Top, Main, Index

Strokes a path with a color or a paint object and optional stroke and line join options.

strokePath image value color options
Parameters
imageThe img::new object to draw on.
valueA string path or a path object created with the pix::path::new Tcl proc.
colorA string color or a paint object created with the pix::paint::new Tcl proc.
optionsA Tcl dict, see attributes below.
Description
Return value

Nothing.

strokeText [::pix::img]Top, Main, Index

This procedure is responsible for rendering text onto an image with various styling options.

strokeText image object text options
Parameters
imageimg.
objectThis can either be a 'arrangement' or a font object.
textIf the object is a font object, this parameter is the text string that needs to be rendered on the image.
optionsCheck out the description below.
Description
Return value

Nothing.

subImage [::pix::img]Top, Main, Index

Gets a sub image from this image.

subImage image coordinates size
Parameters
imageimg::new
coordinateslist x,y
sizelist width,height
Description

The subImage function extracts a portion of the original image starting at (x, y) and spanning the width and height specified.

Return value

A new img object.

superImage [::pix::img]Top, Main, Index

Either cuts a sub image or returns a super image with padded transparency.

superImage image coordinates size
Parameters
imageimg::new
coordinateslist x,y
sizelist width,height
Description

If the coordinates and size of the superImage are within the bounds of the original image, a sub image is cut from the original image.

If the coordinates and size of the superImage are outside the bounds of the original image, a super image is created with the original image centered and padded with transparency. The resulting super image is always the size specified in the arguments.

If the resulting super image is different from the original image, a new image is created. If the resulting super image is the same as the original image, the original image is returned.

Return value

A new img object.

writeFile [::pix::img]Top, Main, Index

Save image file.

writeFile image filePath
Parameters
imageimg::new
filePathstring (*.png|*.bmp|*.qoi|*.ppm)
Return value

Nothing.