BoxLang πŸš€ A New JVM Dynamic Language Learn More...

BoxLang Fluent Image Library

v1.18.0+32 BoxLang Modules

⚑︎ BoxLang Module: BoxLang Image Library

|:------------------------------------------------------: |
| ⚑︎ B o x L a n g ⚑︎
| Dynamic : Modular : Productive
|:------------------------------------------------------: |
Copyright Since 2023 by Ortus Solutions, Corp
www.boxlang.io | www.ortussolutions.com

Β 

Introduction

The BoxLang Image module provides comprehensive image manipulation functionality with a fluent, chainable API. Read, create, transform, filter, and save images with ease. This module brings CFML-compatible image functions to BoxLang while adding modern enhancements and conveniences.

Key Features:

  • πŸ“Έ Read/write images from files, URLs, or Base64
  • πŸ–ΌοΈ Broad format support: PNG, JPEG, WebP, GIF, BMP, TIFF, and SVG (read only, rendered to a raster image)
  • βœ‚οΈ Crop, resize, rotate, flip, scale, split, and shear images
  • 🎨 Draw shapes, text, lines, bezier curves, and points
  • 🎭 Apply filters: blur, sharpen, grayscale, negative
  • πŸ€– Generate CAPTCHA images with configurable difficulty
  • πŸ”³ Generate and read QR codes, with custom colors and an optional logo
  • πŸ“Š Read, write and strip EXIF, IPTC and XMP metadata without re-encoding
  • ⚑ Fluent API with method chaining
  • πŸ”§ 50+ built-in functions and member methods

πŸ“– Full Documentation

Why BoxLang Image?

BoxLang Image brings a fluent, modern API to image manipulation. Unlike traditional tag-based or function-based approaches, BoxLang Image emphasizes method chaining for readable, maintainable code:

// ✨ The Fluent Way (Recommended)
imageRead("photo.jpg")
    .scaleToFit(800, 600)
    .blur(2)
    .sharpen(1)
    .grayScale()
    .write();  // Saves back to original file

// πŸ“¦ Traditional BIF Approach
img = imageRead("photo.jpg");
imageResize(img, 800, 600);
imageBlur(img, 2);
imageSharpen(img, 1);
imageGrayScale(img);
imageWrite(img, "photo.jpg");

// 🏷️ Component Approach
<bx:image action="read" source="photo.jpg" name="img" />
<bx:image action="resize" source="#img#" width="800" height="600" />
<bx:image action="write" source="#img#" destination="photo.jpg" />

The fluent API provides:

  • πŸ”— Method chaining - Write transformations in a natural, sequential flow
  • 🎯 Less boilerplate - No need to repeat variable names
  • πŸ“– Better readability - Code reads like a pipeline of transformations
  • ⚑ Immediate feedback - Each method returns the image for further manipulation

Quick Start

Installation

Install via CommandBox:

# Install the module
install bx-image

# Or add to box.json
box install bx-image --save

Basic Usage

// Read and manipulate an image
img = imageRead( "photo.jpg" )
	.scaleToFit(800, 600)
	.blur(2)
	.sharpen(1)
	.write("photo-optimized.jpg")

// Create a new image with drawing
canvas = imageNew("", 400, 300, "rgb", "white")
canvas.setDrawingColor("blue")
      .drawRect(50, 50, 300, 200, true)
      .setDrawingColor("red")
      .drawText("Hello BoxLang!", 150, 150)
	  .write("greeting.png")

// Chain operations
imageRead("logo.png")
    .crop(10, 10, 200, 200)
    .grayScale()
    .rotate(45)
    .write("logo-transformed.png")

Quick Reference

Fluent BoxImage API

The BoxImage class provides a fluent interface where most methods return this for chaining:

Image Creation & I/O

img = imageRead("path/to/file.jpg")          // Load from file
img = imageRead("https://example.com/img")   // Load from URL
img = imageRead("logo.svg")                  // Render an SVG at its intrinsic size
img = imageRead("logo.svg", 800)             // Render an SVG straight at 800px wide
img = imageReadBase64(base64String)          // Load from Base64
img = imageNew("", 800, 600, "rgb", "white") // Create blank canvas

img.write("output.png")                      // Write to specified file (format from extension)
img.write()                                  // Write back to original source file
base64 = imageWriteBase64(img)               // Export as Base64
base64 = imageWriteBase64(img, "jpg")        // Export as Base64 with format
blob = imageGetBlob(img)                     // Export as binary
imageWriteToBrowser(img)                     // Stream directly to HTTP response
formats = GetReadableImageFormats()          // List readable formats
formats = GetWriteableImageFormats()         // List writable formats

Note: The write() and ImageWrite() methods auto-detect the output format from the file extension (e.g., .png, .jpg, .webp, .gif, .bmp, .tiff). For formats that don't support transparency (JPEG, BMP), images with alpha channels are automatically composited onto a white background.

Transformations

img.resize(width, height)                    // Exact dimensions
img.resize(width, height, interpolation)     // With interpolation method
img.scaleToFit(size)                         // Fit to width, maintain aspect ratio
img.scaleToFit(width, height)                // Fit within rectangular bounds
img.scaleToFit(width, height, interpolation) // With custom interpolation
img.crop(x, y, width, height)                // Extract region
img.rotate(angle)                            // Rotate clockwise in degrees
img.rotate(angle, interpolation)             // nearest (default), bilinear, or bicubic
img.rotate(x, y, angle)                       // Rotate around an explicit pivot
img.rotate(x, y, angle, interpolation)        // Explicit pivot with interpolation
img.flip("horizontal")                       // Flip horizontal
img.flip("vertical")                         // Flip vertical
img.flip("diagonal")                         // Flip along main diagonal (transpose)
img.flip("antidiagonal")                     // Flip along anti-diagonal
img.flip("90")                               // Rotate 90Β° clockwise
img.flip("180")                              // Rotate 180Β°
img.flip("270")                              // Rotate 270Β° clockwise (90Β° CCW)
img.shear(shearX, shearY)                    // Shear transform
img.rotateDrawingAxis(angle)                 // Rotate drawing axis
img.translateDrawingAxis(x, y)               // Translate drawing axis
img.shearDrawingAxis(shearX, shearY)         // Shear drawing axis

Rotation expands the canvas to fit the rotated image. The ImageRotate() function accepts the same arguments with the image first:

ImageRotate(img, 90)
ImageRotate(img, 200, 150, 90, "bilinear")
ImageRotate(image=img, x=200, y=150, angle=90)

Named function calls accept image or its backward-compatible alias name for the image argument.

Filters & Effects

img.blur(radius)                             // Apply Gaussian blur
img.sharpen(gain)                            // Sharpen image
img.grayScale()                              // Convert to grayscale
img.negative()                               // Invert colors
img.addBorder(thickness, color)              // Add colored border

Drawing Setup

img.setDrawingColor("red")                   // Set foreground color
img.setDrawingColor("#FF0000")               // Use hex colors
img.setBackgroundColor("white")              // Set background
img.setAntiAliasing(true)                    // Enable anti-aliasing
img.setDrawingTransparency(50)               // Set transparency (0-100)
img.setDrawingStroke({                       // Set stroke properties
    width: 2.0,                              // Stroke width in pixels
    endCaps: "round",                        // "butt", "round", or "square"
    lineJoins: "miter",                      // "miter", "round", or "bevel"
    miterLimit: 10.0,                        // Miter limit for mitered joins
    dashArray: [10, 5],                      // Dash pattern (on, off, on, off...)
    dashPhase: 0                             // Offset to start dash pattern
})

Drawing Shapes

img.drawRect(x, y, width, height, filled)    // Rectangle
img.drawRoundRect(x, y, w, h, aw, ah, fill)  // Rounded rectangle
img.drawBeveledRect(x, y, w, h, raised, fill)// Beveled rectangle
img.drawOval(x, y, width, height, filled)    // Oval/circle
img.drawArc(x, y, w, h, start, arc, filled)  // Arc segment
img.drawLine(x1, y1, x2, y2)                 // Straight line
img.drawLines(pointArray, isPolygon, filled) // Multiple lines/polygon
img.drawPoint(x, y)                          // Single pixel
img.drawCubicCurve(x1, y1, cx1, cy1, ...)    // Bezier curve
img.drawQuadraticCurve(x1, y1, cx, cy, ...)  // Quadratic curve
img.clearRect(x, y, width, height)           // Clear region

Drawing Text

img.drawText(text, x, y)                     // Draw text at position
img.drawText(text, x, y, attributes)         // With font attributes
// attributes: { font, size, style, alpha, underline, strikethrough }

Image Composition

img.overlay(topImage)                        // Overlay another image
img.paste(source, x, y)                      // Paste at position
img.copy(x, y, width, height)                // Copy region to new image

Image Splitting

// Split into a grid of tiles (returns array of arrays)
tiles = img.splitGrid(columns, rows)          // 2D array: tiles[row][col]
tiles = ImageSplitGrid(img, columns, rows)    // BIF equivalent

// Example: split a 600Γ—400 image into 3Γ—2 grid (6 tiles, each 200Γ—200)
grid = ImageRead("panorama.jpg").splitGrid(3, 2);
// grid[1][1] = top-left, grid[1][2] = top-center, etc.
eachTile = grid[2][1];  // second row, first column

Image Information

width = img.getWidth()                       // Get width in pixels
height = img.getHeight()                     // Get height in pixels
info = imageInfo(img)                        // Full image info struct
pixels = img.getPixels()                     // Rows of luma values (0-255); "rgba" for [r,g,b,a]
exif = imageGetExifMetadata(img)             // EXIF metadata
tag = imageGetExifTag(img, tagName)          // Specific EXIF tag
iptc = imageGetIPTCMetadata(img)             // IPTC metadata
tag = imageGetIPTCTag(img, tagName)          // Specific IPTC tag
xmp = imageGetXMP(img)                       // XMP packet
img.setExifTag("Artist", "Jane")             // Written with the image
img.setIPTCTag("Keywords", ["a", "b"])
img.setXMP(xmpString)
meta = imageReadMetadata("photo.jpg")        // Edit a file's metadata without decoding it
meta.setExifTag("Copyright", "(c) 2026").write()
imageStripMetadata("upload.jpg")             // Remove all metadata in place
buffered = imageGetBufferedImage(img)        // Java BufferedImage

Creating Images

// From file
img = imageRead("path/to/image.jpg");

// From URL
img = imageRead("https://example.com/image.png");

// From Base64
img = imageReadBase64(base64String);

// New blank canvas
img = imageNew("", 800, 600, "rgb", "white");

Reading SVG

imageRead(), imageNew(), imageReadBase64() and the image component read SVG files and return a regular raster image, so every other image function works on it. SVG is detected by the .svg extension or by content (an <svg root element after an optional XML prolog, comments or doctype).

// Intrinsic size: the SVG's width and height, else its viewBox, else 512 x 512
logo = imageRead( "logo.svg" );

// Render straight at a target size so it stays sharp. One side keeps the aspect ratio.
logo = imageRead( path = "logo.svg", width = 800 );
logo = imageRead( path = "logo.svg", height = 200 );
logo = imageRead( "logo.svg", 256, 256 ); // fitted into the box per the SVG's preserveAspectRatio

logo.grayScale().write( "logo.png" );
  • The image is ARGB, so transparency is kept. It encodes as PNG by default, since SVG cannot be written back.
  • width and height on imageRead() also work for other formats, which are decoded and then resized.
  • The rendered size is checked against maxPixels before any pixels are allocated.
  • External resources (linked images, fonts, file: or http: references) are never loaded. Only embedded data: resources render. DTDs and external XML entities are disabled.
  • A malformed SVG throws Unable to load image: <source>, caused by Unable to read SVG image [...]: the content is not a well-formed SVG document.
  • Rendering uses JSVG. SVG animation and scripting are not supported.

CAPTCHA Generation

// Basic CAPTCHA (args: height, width, text)
captcha = ImageGenerateCaptcha( 75, 200, "A3X9K2" );
ImageWrite( captcha, "/path/to/captcha.png" );

// With difficulty and fonts (ColdFusion-compatible arg order)
captcha = ImageGenerateCaptcha( 35, 400, "loner" );
captcha = ImageGenerateCaptcha( 35, 400, "loner", "high" );
captcha = ImageGenerateCaptcha( 35, 400, "loner", "high", "serif,sansserif", 24 );

// Via component β€” auto-streams to browser when no name/destination is given
<bx:image action="captcha" text="A3X9K2" width="200" height="75" difficulty="medium" />

// Store in variable for further processing
<bx:image action="captcha" text="A3X9K2" width="200" height="75" name="captchaImg" />

// Write directly to file
<bx:image action="captcha" text="A3X9K2" destination="/path/to/captcha.png" />

Difficulty levels:

  • low β€” minimal character rotation, clean background
  • medium β€” moderate rotation, noise dots, crossing lines
  • high β€” heavy rotation, dense noise, wavy lines, random character colors

QR Codes

Generate a QR code from text. The result is a regular image, so ImageWrite(), ImageResize(), ImageWriteBase64() and the rest of the image functions all work on it.

// Basic QR code, 125px PNG
qr = ImageQRCodeGenerate( "https://example.com/verify" );
ImageWrite( qr, "/path/to/qr.png" );

// text, size, format, errorCorrection, quietZone
qr = ImageQRCodeGenerate( "ME:12345678", 250, "gif", "H" );

// Colors and a logo
qr = ImageQRCodeGenerate(
    text       = "https://example.com",
    size       = 400,
    foreground = "#1a237e",
    background = "white",
    logo       = "/path/to/logo.png"
);

// Member function on a string
qr = "https://example.com".toQRCode( 250 );

// Read a QR code back out of an image (empty string if none is found)
text = ImageQRCodeRead( ImageRead( "/path/to/qr.png" ) );
text = qr.readQRCode();

// Via component
<bx:image action="qrcode" text="https://example.com" size="250" name="qr" />
<bx:image action="qrcode" text="https://example.com" destination="/path/to/qr.png" />
<bx:image action="qrread" source="/path/to/qr.png" name="decoded" />

Arguments of ImageQRCodeGenerate():

Argument Default Description
text requiredThe text to encode.
size 125 Edge length in pixels, clamped to 16 to 4096.
format png Any format returned by GetWriteableImageFormats().
errorCorrection M L, M, Q or H. Always H when a logo is used.
quietZone 4 Light margin in modules, clamped to 0 to 32.
foreground black Color of the dark modules. A color name or hex code.
background white Color of the light modules. A color name or hex code.
logo noneAn image, file path or URL drawn in the center.
logoScale 0.2 Fraction of the code's edge the logo covers, up to 0.3.

A logo hides part of the code. If a logo would make the code unreadable, for example a large logo on a very short text, ImageQRCodeGenerate() throws instead of returning a code that will not scan. Lower logoScale, raise size, or encode more text.

Member Functions vs BIFs

Most functions work both ways:

// As BIF (Built-In Function)
imageBlur(img, 5);
imageCrop(img, 10, 10, 200, 200);

// As member function (chainable!)
img.blur(5)
   .crop(10, 10, 200, 200)
   .write();

BIFs

This module contributes the following BIFs:

Most of these BIFs are also implemented as member functions on the BoxImage type, so imageGrayScale( myImage ) can also be written as myImage.grayScale().

Components

This module provides the <bx:image> component for tag-based image manipulation.

Quick Reference

The <bx:image> component supports the following actions:

// Read an image
<bx:image action="read" source="photo.jpg" name="myImage" />

// Resize
<bx:image action="resize" source="#myImage#" width="800" height="600" />

// Rotate
<bx:image action="rotate" source="#myImage#" angle="45" destination="rotated.jpg" />

// Add border
<bx:image action="border" source="#myImage#" color="black" thickness="5" />

// Write to file
<bx:image action="write" source="#myImage#" destination="output.jpg" />

// Get image info
<bx:image action="info" source="#myImage#" structName="imageInfo" />

// Write to browser
<bx:image action="writeToBrowser" source="#myImage#" />

Supported Actions:

  • read - Load an image from file or URL
  • write - Save image to file
  • writeToBrowser - Stream image to HTTP response (supports format attribute)
  • resize - Change image dimensions
  • rotate - Rotate image by angle
  • border - Add border around image
  • info - Get image metadata
  • convert - Convert image format
  • captcha - Generate a CAPTCHA image (v1.6.0+)
  • qrcode - Generate a QR code image
  • qrread - Read the text from a QR code into the variable named by name

Common Attributes:

  • source - Path to image file, URL, or BoxImage variable
  • name - Variable name to store the image
  • destination - Output file path for write operations
  • width, height - Dimensions for resize
  • angle - Rotation angle in degrees
  • color - Color name or hex code
  • thickness - Border thickness in pixels
  • overwrite - Boolean, allow overwriting existing files (default: false)
  • isBase64 - Boolean, indicates if source is Base64-encoded

πŸ’‘ Tip: For complex image manipulation workflows, consider using the fluent API instead of components for better readability and maintainability.

Settings

Set these under the bx-image module settings in boxlang.json.

Setting Default Description
maxPixels 50000000 Maximum width x height an image may declare. Checked from the header before decoding. 0 disables.
maxBytes 52428800 Maximum source size in bytes for files, URLs and Base64 data. 0 disables.

Image Sources

imageNew() and imageRead() accept the same sources:

Source Example
http: or https: URLimageRead( "https://example.com/logo.png" )
file: URIimageRead( "file:///tmp/logo.png" )
Relative path, resolved from the current template and mappingsimageRead( "images/logo.png" )
Absolute path, including Windows drive paths with \ or / imageRead( "D:\\a\\x\\card.png" ), imageRead( "C:/x/card.png" )

Anything that is not an http:, https: or file: URI is treated as a local path and resolved with expandPath(). A source that cannot be loaded throws Unable to load image: <source>.

Important Notes

File Handling

The module properly manages file handles when reading images. After loading an image with imageRead() or imageNew(), the underlying file stream is automatically closed, allowing you to safely delete or move the source file:

// This works correctly - file can be deleted after reading
img = imageRead("photo.jpg");
img.resize(800, 600).write("photo-resized.jpg");
fileDelete("photo.jpg");  // βœ… Works - no file lock

This is especially important on Windows, where file locks can prevent file operations.

Directory Creation

When writing images, parent directories are automatically created if they don't exist:

// Creates 'output/thumbs/' directory if needed
img.write("output/thumbs/photo.jpg");

Format Detection

The write() and ImageWrite() methods now auto-detect the output format from the file extension rather than defaulting to PNG. For example:

// Correctly writes JPEG, WebP, GIF, BMP, or TIFF based on extension
img.write("photo.jpg");   // β†’ JPEG
img.write("photo.webp");  // β†’ WebP
img.write("photo.gif");   // β†’ GIF
img.write("photo.bmp");   // β†’ BMP
img.write("photo.tiff");  // β†’ TIFF

Alpha Channel Handling

When writing to formats that do not support transparency (JPEG, BMP), images with alpha channels are automatically composited onto a white background. This prevents write failures and produces visually correct output.

MatchBox (native) backend

The same bx-image package also runs on MatchBox, with no JVM. The release zip carries a native plugin next to the JVM jar, and MatchBox picks it up from matchbox.artifacts in box.json. It covers a portable subset of the API:

  • imageRead( path, [width], [height] ) and imageNew( path ): PNG, JPEG, GIF, WebP and SVG (detected by extension or by content)
  • imageNew( "", width, height, [imageType], [color] ): blank images
  • imageResize() / img.resize(): SVG images are redrawn at the new size, so they stay sharp
  • imageGrayScale() / img.grayScale(), imageInfo() / img.info(), imageGetPixels() / img.getPixels(), getReadableImageFormats()

Anything else fails with a clear error on MatchBox. See native/README.md for details and for building the plugin.

Examples

Blur, crop, and grayscale a png image before saving it back to disk:

var updatedLogo = ImageRead( "src/test/resources/logo.png" )
    .blur( 5 )
    .crop( x = 50, y = 50, width = 150, height = 100 )
    .grayScale();
imageWrite( updatedLogo, "src/test/resources/logoNew.png" );

Third-Party Licenses

Metadata writing is provided by pixymeta, licensed under the Eclipse Public License 1.0. The licence text is shipped in licenses/pixymeta-EPL-1.0.txt; the library is bundled unmodified.

The source code for the bundled pixymeta 1.4.0 is available at https://github.com/akitogo/pixymeta/tree/v1.4.0.

Ortus Sponsors

BoxLang is a professional open-source project and it is completely funded by the community and Ortus Solutions, Corp. Ortus Patreons get many benefits like a cfcasts account, a FORGEBOX Pro account and so much more. If you are interested in becoming a sponsor, please visit our patronage page: https://patreon.com/ortussolutions

THE DAILY BREAD

"I am the way, and the truth, and the life; no one comes to the Father, but by me (JESUS)" Jn 14:1-12

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.


Unreleased

1.18.0 - 2026-11-30

Changed

  • ImageReadMetadata() streams local files instead of loading them into memory: pixymeta reads a JPEG only up to the image data (other formats to the end of the file), getExif() and getIPTC() read the file as a stream (with pending changes through a temporary copy), and write() copies the image data from the file. maxBytes therefore no longer limits local files here, nor the functions that open a handle on a path (ImageGetXMP(), ImageSetExifTag(), ImageSetIPTCTag(), ImageSetXMP(), ImageRemoveMetadata(), ImageStripMetadata() and the MetaData variants). It still applies to URLs and to toBinary() / toBase64(), which hold the whole image in memory.

Fixed

  • The documentation of getIPTCTag() on a metadata handle: several values of a repeatable tag such as Keywords come back joined with ;, the same as ImageGetIPTCTag().
  • BL-2825 imageRotate compatibility/enhancements

1.17.0 - 2026-11-25

Added

  • Metadata writing. EXIF, IPTC and XMP can now be written, backed by the pixymeta library (EPL-1.0, see licenses/). Two entry points:
    • ImageReadMetadata( source ) returns a metadata handle for a file or URL without decoding the image. It has getters (getExif(), getIPTC(), getXMP(), getExifTag(), getIPTCTag(), getTypes(), getFormat()), chainable setters (setExifTag(), setExifMetaData(), setIPTCTag(), setIPTCMetaData(), setXMP(), setICCProfile(), removeExifTag(), removeIPTCTag(), remove(), removeAll()) and writers (write() in place via a temporary file, write( destination ), toBinary(), toBase64()). The image data is copied byte for byte, so editing metadata is lossless and fast, and metadata the handle was not told about stays.
    • ImageStripMetadata( source [, destination [, types ]] ) removes all or some metadata from a file without re-encoding it.
    • The same setters on images: ImageSetExifTag(), ImageSetExifMetaData(), ImageSetIPTCTag(), ImageSetIPTCMetaData(), ImageSetXMP(), ImageGetXMP() and ImageRemoveMetadata(), each also as a member function. On an image object the metadata is stamped onto the encoded bytes in write(), toByteArray() and toBase64String(); on a file path the file is rewritten in place. A plain write() without setters produces the same file as before, and source metadata is still not carried through pixel edits.
    • Tag names accept the display names the getters return (Date/Time Original, Copyright Notice, By-line), the specification names (DateTimeOriginal, CopyrightNotice) and common aliases (ISO, Copyright, Caption, Creator). Values may be strings, numbers, dates or arrays (for repeatable IPTC tags such as Keywords); a decimal GPSLatitude / GPSLongitude also sets the N/S or E/W reference. Setting a tag to null removes it.
    • JPEG and TIFF take EXIF, IPTC, XMP and ICC; WebP takes EXIF, XMP and ICC; PNG takes XMP and ICC; GIF takes XMP. An unsupported combination such as EXIF in a PNG throws a clear error instead of silently writing nothing.
    • ImageGetExifTag(), ImageGetExifMetaData(), ImageGetIPTCTag() and ImageGetIPTCMetadata() also accept a metadata handle.
  • ImageReadBase64() now exposes the EXIF and IPTC metadata embedded in the Base64 data, like images read from a file.

Fixed

  • Path-based EXIF and IPTC metadata getters now close their input streams before returning, so files can be replaced or have metadata removed in place on Windows without an AccessDeniedException. They also handle Windows absolute paths, paths containing spaces and file: URIs correctly.

1.16.0 - 2026-11-20

Fixed

  • The MatchBox native plugin in the release zip needed glibc 2.43 (it was built on Ubuntu 26.04), so it would not load on older Linux systems. It is now built with cargo zigbuild against glibc 2.28, and CI fails if the library needs anything newer. Set MATCHBOX_GLIBC to choose the baseline when packaging.

1.15.0 - 2026-11-17

Added

  • MatchBox native backend: the bx-image package now also runs on MatchBox without a JVM. It reads PNG, JPEG, GIF, WebP and SVG (imageRead with its optional width and height, imageNew), and supports imageResize, imageGrayScale, imageInfo, imageGetPixels and getReadableImageFormats, with the resize(), grayScale(), info() and getPixels() member functions. SVG images are redrawn when resized. The release zip carries the native plugin for x86_64-unknown-linux-gnu alongside the JVM jar.
  • ImageGetPixels( name, [mode] ) and img.getPixels( [mode] ) on both backends: the pixels as an array of rows, as luma values (luma, the default) or [r, g, b, a] arrays (rgba).
  • SVG read support. imageRead(), imageNew(), imageReadBase64() and the image component render SVG files to an ARGB raster image, so every other image function (resize, grayScale, write, ...) works on them. SVG is detected by the .svg extension or by content (an <svg root after an optional XML prolog). The image uses the SVG's intrinsic size from its width and height or viewBox, or 512 x 512 when it declares neither, and encodes as PNG by default.
  • imageRead() takes optional width and height arguments. An SVG is rendered straight at that size so it stays sharp; other formats are decoded and then resized. With one side given, the other keeps the aspect ratio.
  • GetReadableImageFormats() includes svg.
  • BoxImage( String, Integer, Integer ), BoxImage( URI, Integer, Integer ) and BoxImage.fromSvg() on the Java API.
  • JSVG (com.github.weisj:jsvg, MIT, no dependencies) is now bundled for SVG rendering. External resources are never loaded and the rendered size is checked against maxPixels.

Changed

  • ImageResize() and img.resize() accept a blank or 0 width or height and keep the aspect ratio from the other dimension.
  • imageGetExifMetaData() and imageGetExifTag() report Exposure Time as a fraction, such as 1/100 sec instead of 0.01 sec, following the metadata-extractor 2.22.0 update.

1.14.0 - 2026-10-30

Fixed

  • imageNew() with a Windows absolute path such as D:\a\x\card.png failed with Unable to load image: null, because every non-empty source was parsed as a URI. Only http:, https: and file: sources are treated as URIs now. Any other string is a local path resolved with expandPath(), the same as imageRead(), so relative paths and mappings keep working.
  • imageRead() threw a StringIndexOutOfBoundsException for paths shorter than 4 characters. It now reports Unable to load image: <path>.
  • Windows drive paths with forward slashes such as C:/x/card.png were parsed as a URI with scheme C. BoxImage.stringToURI() now converts any drive path to a file: URI, and BoxImage.isWindowsDrivePath() and BoxImage.isURISource() are available on the Java API.
  • The imageNew() load error message printed null instead of the source that failed.

Security

  • BL-2767: Images are no longer decoded blindly. imageNew(), imageReadBase64(), the image component and the image cache check the declared width x height from the image header before allocating any pixels, and reject images over the new maxPixels module setting (default 50,000,000). The source size is also capped by the new maxBytes setting (default 50 MB) for files, URLs and Base64 data. isImageFile() now answers from the header alone, so it is much faster and returns false for images over the limits instead of decoding them. An OutOfMemoryError during decoding is rethrown as a BoxRuntimeException. Set either setting to 0 to disable that limit.

1.13.0 - 2026-10-19

Added

  • drawText() accepts a file key in its font attribute struct pointing at a .ttf or .otf font file, used instead of font. ImageRegisterFont( path ) loads and registers a font file and returns its family name so it can be used as font. A missing, empty or invalid font file throws a clear error. Font resolution is a single code path shared with drawing, so any measurement built on it uses the same font.
  • ImageMeasureText( name, str [, attributeCollection] ) and the member function measureText() return the rendered width, height, ascent, descent and leading of a line of text, using the same font attribute struct and font resolution as drawText(). Use it to word wrap or shrink text to fit. A wrapText helper is intentionally not included; see the docs for a short wrapping recipe built on measureText().
  • ImageSetDrawingGradient( name, x1, y1, x2, y2, colors [, fractions] ) and the member function setDrawingGradient() set a linear gradient as the paint for subsequent fills, strokes, lines and text. setDrawingColor() returns to a solid color. Invalid input (fewer than two colors, bad color, identical points, bad fractions) throws.

Fixed

  • Hex color strings were silently ignored: setDrawingColor( "#FF00FF" ) kept the previous color (black on a fresh image) and imageNew( "", 10, 10, "rgb", "#0b161b" ) gave a white background. Colors now accept #RGB, #RRGGBB and #RRGGBBAA (alpha last, # optional) in setDrawingColor, setBackgroundColor, ImageNew, ImageAddBorder and <bx:image action="border">. An unparseable color now throws instead of being ignored, and leaves the current color unchanged. Remember that a literal # must be written ## in a BoxLang string.

1.12.0 - 2026-10-14

Added

  • ImageQRCodeGenerate() creates a QR code image from text. It takes size, format, errorCorrection, quietZone, foreground, background, logo and logoScale, returns a regular image so every other image function works on it, and is also available as the string member function toQRCode(). A logo forces error correction level H, and a logo that would make the code unreadable throws instead of returning a code that will not scan.
  • ImageQRCodeRead() returns the text of a QR code in an image, or an empty string when there is none. It is also available as the image member function readQRCode().
  • <bx:image action="qrcode"> and <bx:image action="qrread">, matching the existing captcha action for output and name, destination and overwrite handling.
  • BoxImage.generateQRCode(), BoxImage.readQRCode() and BoxImage.setFormat() on the Java API.
  • ZXing (com.google.zxing:core and javase) is now bundled for QR encoding and decoding.

1.11.0 - 2026-09-26

Fixed

  • ImageReadBase64() and BoxImage.fromBase64() always reported the image's format as the hardcoded default ("jpg") regardless of what was actually decoded, because format detection only ever inspected sourcePath's file extension - and a base64-decoded image never has a source path. figureOutFormat() now also consults the real file type detected from the decoded bytes themselves (via the same com.drew.imaging.FileTypeDetector magic-byte detection already used for file/URI-loaded images), so getFormat() correctly reports "png", "gif", "webp", etc. for the actual decoded format instead of always falling back to "jpg". This also makes format detection for ImageRead()/file-path loading robust against a source file whose extension doesn't match its real contents.

1.10.0 - 2026-09-02

Fixed

  • ImageRead() now uses the bundled pure-Java WebP reader, and the native WebP writer now includes an Apple Silicon binary. WebP reading and writing are both supported on Apple Silicon.

1.9.0 - 2026-08-22

Fixed

  • ImageIO's WebP writer/reader (webp-imageio, imageio-webp, bundled in this module's own libs/) was never discovered when this module ran inside a host that gives it its own isolated ClassLoader (e.g. BoxLang's own per-module ClassLoader - see ModuleConfig.bx's own docblock). javax.imageio.ImageIO's static plugin registry is built once, lazily, using whichever thread's context classloader is active the very first time anything in the whole JVM process touches ImageIO - which may not be this module's own classloader at all, and is never rescanned automatically afterward. BoxImage's own static initializer now explicitly forces a rescan (ImageIO.scanForPlugins()) using its own classloader, so the bundled WebP plugins are always found regardless of load order or which classloader first touched ImageIO. Previously, .write("*.webp") could fail with "No suitable ImageIO writer found for format: webp" even though the writer was right there on this module's own classpath.

1.8.0 - 2026-07-25

Fixed

  • ImageReadBase64() and BoxImage.fromBase64() now accept data URIs with a data:image/<format>;base64, prefix, matching the output format produced by ImageWriteBase64() and ImageService.writeImageToBrowser().

1.7.0 - 2026-06-01

Added

  • WebP image format support for reading and writing via the org.sejda.imageio:webp-imageio ImageIO plugin. All BIFs that read or write images (ImageRead, ImageWrite, ImageWriteBase64, ImageReadBase64, IsImageFile) now handle WebP natively.
  • GIF image format support for reading and writing. Java's built-in ImageIO GIF codec is now fully exposed through ImageRead, ImageWrite, and ImageWriteBase64.
  • BMP image format support for reading and writing, with automatic ARGBβ†’RGB conversion on write (BMP does not support alpha channels).
  • TIFF image format support for reading and writing via Java 9+ built-in ImageIO plugin.
  • GetReadableImageFormats() and GetWriteableImageFormats() now include webp, gif, bmp, and tiff in their results.

Fixed

  • ImageWrite and img.write(path) were hardcoded to always produce PNG data regardless of the destination file extension. Writing to .jpg, .webp, or any non-PNG path now correctly encodes in the target format.
  • Writing an image with an alpha channel to JPEG or BMP no longer fails β€” the image is automatically composited onto a white background before encoding, since these formats do not support transparency.

Updated

  • Replaced org.apache.commons.imaging.Imaging.writeImage() with javax.imageio.ImageIO.write() as the underlying write mechanism, enabling format detection from the file extension and support for any registered ImageIO plugin (JPG, PNG, WebP, GIF, BMP, TIFF).
  • Added com.twelvemonkeys.imageio:imageio-webp as a pure-Java WebP reader, ensuring WebP reading works cross-platform including macOS ARM64 (Apple Silicon). WebP writing still requires the native webp-imageio library which supports Linux and Intel macOS; on unsupported platforms a clear BoxRuntimeException is thrown instead of a raw UnsatisfiedLinkError.

1.6.0 - 2026-05-25

Added

  • ImageGenerateCaptcha( height, width, text [, difficulty [, fonts [, fontSize]]] ) BIF for generating CAPTCHA images with configurable dimensions, font size, difficulty level (low/medium/high), and font list. Argument order is ColdFusion-compatible.
  • <bx:image action="captcha"> component support with text, width, height, fontSize, difficulty, fonts, destination, overwrite, and name attributes. When neither name nor destination is specified, the image is automatically streamed to the browser.

Fixed

  • javaxt.com has been down for weeks, moving to single compiled jar and looking for alternatives.
  • ModuleConfig.bx version was not dynamic.

1.5.0 - 2026-02-18

  • BLMODULES-139 Update writeToBrowser to accept format attribute
  • BLMODULES-138 Improve base64 generation and auto detect format

1.4.0 - 2025-11-12

Added

  • Updated all GitHub actions to latest according to templates
  • Updated templates to latest module template
  • Bump javaxt:javaxt-core from 2.1.9 to 2.1.11
  • Generate AI Instructions
  • Dependabot updates
  • Updated Gradle wrapper to 8.14.1
  • Updated gradle build to latest module template
  • Added documentation to classes

Changed

  • All tests to inherit from BaseIntegrationTest for consistency
  • Refactored internal classes into functional packaging
  • Rewrote the ImageDrawTextTest to use more reliable image size assertions and work on all Operating Systems

Fixed

  • Resource leak when reading images into the input stream and not closing it.
  • Added jaxt library to gradle dependencies
  • Fixed writing of images to directories that don't exist. Now creates parent directories as needed.
  • image.scaleToFit() now works with a single value and more.
  • write() now works with no provided path, uses internally read source path.

1.3.2 - 2025-07-25

Changed

  • Removed logging from ImageService startup/shutdown

1.3.1 - 2025-07-24

Changed

  • Version bump maintenance release

1.3.0 - 2025-07-23

Fixed

  • BL-1216 Fix ImageScaleToFit BIF
  • BL-1217 Fix invoking resize as a member function

1.1.0 - 2025-02-13

1.0.1 - 2024-06-27

1.0.0 => 2024-APR-05

  • First iteration of this module

$ box install bx-image

No collaborators yet.
     
  • {{ getFullDate("2024-05-14T19:58:48-05:00") }}
  • {{ getFullDate("2026-11-30T10:02:45-06:00") }}
  • 5,450
  • 67,906