The image module provides comprehensive functionalities for working with images, including loading, decoding, creating new images, applying filters, and encoding images into various formats.
Creates a new image with the specified width and height.
width: Width of the new image (integer)height: Height of the new image (integer)
Loads an image from the specified file path.
path: Path to the image file (string)
Decodes image data into an image object.
image_data: Byte array containing image data (bytes)
Array containing supported image formats: ["png", "jpeg", "bmp", "tiff", "webp"]
Encodes the image into the specified format and returns byte data.
format: Format to encode the image ("png", "jpeg", "bmp", "tiff")
Returns the bounding rectangle of the image as an object with:
min: Object withx,ycoordinatesmax: Object withx,ycoordinatessize: Object withwidth,heightdimensions
Returns the color of the pixel at the specified coordinates as RGBA array.
x: X-coordinate of the pixel (integer)y: Y-coordinate of the pixel (integer)
Returns the total number of pixels in the image (integer).
Returns a flat array containing all pixel values of the image.
Sets the pixel values of the image from the given array.
pixels: Array containing pixel values (array)
Sets the color of the pixel at the specified coordinates.
x: X-coordinate of the pixel (integer)y: Y-coordinate of the pixel (integer)color: Array containing RGBA values[red, green, blue, alpha](array)
Saves the image to the specified file path and format.
path: Path to save the image (string)format: Format to save the image ("png", "jpeg", "bmp", "tiff")
The filters object provides various image filter operations that return new filtered images:
Applies Gaussian blur with specified radius.
radius: Blur radius (integer)
Converts image to black and white using luminance threshold.
threshold: Luminance threshold (0-255)
Applies glitch effect by randomly shifting RGB channels.
max_shift: Maximum pixel shift amount (integer)
Inverts all colors in the image.
Converts image to grayscale.
Applies sepia tone filter.
Adjusts brightness by adding offset to each channel.
offset: Brightness adjustment (-255 to 255)
Adjusts contrast by multiplying difference from middle gray.
factor: Contrast multiplier (float)
Adjusts color saturation.
factor: Saturation multiplier (0 = grayscale, 1 = original)
Applies sharpening filter.
Applies emboss effect.
Applies edge detection filter.
Adjusts hue by specified angle.
angle: Hue angle in degrees (float)
Adjusts color temperature.
adjustment: Temperature adjustment (positive = warmer, negative = cooler)
Applies vignette (darkened edges) effect.
intensity: Vignette strength (float)
Creates pixelated effect with specified block size.
size: Pixel block size (integer)
Applies Sobel edge detection operator.
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")Colors are represented as arrays of 4 integers: [red, green, blue, alpha] where each component ranges from 0 to 255.
- All filter operations are parallelized for optimal performance
- Filters return new image objects and do not modify the original
- Large images may require significant memory and processing time
- The module maintains image data in RGBA format internally
- PNG: Lossless compression with transparency support
- JPEG: Lossy compression suitable for photographs
- BMP: Uncompressed bitmap format
- TIFF: High-quality format with various compression options
- WebP: Modern format with both lossy and lossless compression