The image
module provides functionalities for working with images, including loading, decoding, creating new images, and encoding images into various formats.
Creates a new image with the specified width and height.
width
: Width of the new image.height
: Height of the new image.
Loads an image from the specified file path.
path
: Path to the image file.
Decodes image data into an image object.
image_data
: Byte array containing image data.
Array containing supported image formats: PNG, JPEG, BMP, TIFF, and WebP.
Encodes the image into the specified format.
format
: Format to encode the image (e.g., "png", "jpeg", "bmp", "tiff").
Returns the bounding rectangle of the image.
Returns the color of the pixel at the specified coordinates.
x
: X-coordinate of the pixel.y
: Y-coordinate of the pixel.
Returns the total number of pixels in the image.
Returns an array containing the pixel values of the image.
Sets the pixel values of the image from the given array.
pixels
: Array containing pixel values.
Sets the color of the pixel at the specified coordinates.
x
: X-coordinate of the pixel.y
: Y-coordinate of the pixel.color
: Array containing RGBA values of the color.
Saves the image to the specified file path and format.
path
: Path to save the image.format
: Format to save the image (e.g., "png", "jpeg", "bmp", "tiff").
import "image"
// Create a new image
img := image.new(255, 255)
for i := 0; i < 255; i++ {
for j := 0; j < 255; j++ {
color := [i, 0, j, 255]
img.set(i, j, color)
}
}
img.save("out.png", "png")