Fluent Builder
The BoxImage class provides a fluent, chainable API for image manipulation in BoxLang. All methods return the BoxImage instance, allowing you to chain multiple operations together in a single expression.
Creating Images
ImageNew()
Create a new image from various sources:
// From file path
img = ImageNew("images/photo.jpg");
// From URL
img = ImageNew("https://example.com/image.png");
// From base64 string
img = ImageReadBase64(base64String);
// Blank canvas
img = ImageNew(800, 600);
img = ImageNew(800, 600, "rgb");
img = ImageNew(800, 600, "rgb", "white");Transformations
resize(width, height, [interpolation], [blurFactor])
Resize the image to specific dimensions.
Interpolation methods: nearest, bilinear, bicubic, highestPerformance, highestQuality
scaleToFit(size, [interpolation])
Scale image proportionally to fit within a bounding box.
rotate(angle)
Rotate the image by degrees (clockwise).
crop(x, y, width, height)
Crop a rectangular region from the image.
transpose(operation)
Flip or rotate the image in various ways.
Aliases: flip() is an alias for transpose()
translate(x, y)
Move the image content by offset.
shear(amount, dimension)
Shear the image horizontally or vertically.
Color Adjustments
grayScale()
Convert the image to grayscale.
negative()
Invert the colors (create a negative).
Filters & Effects
blur([radius])
Apply a blur effect.
sharpen(gain)
Sharpen the image.
addBorder(thickness, color)
Add a solid border around the image.
Colors: Accepts color names ("red", "blue", "black") or hex codes ("#FF0000")
Compositing
overlay(imageToOverlay, overlayRule, transparency)
Overlay another image on top of this one.
Overlay rules: normal, add, subtract, difference, multiply, screen, overlay, hardlight, softlight
drawImage(image, x, y)
Draw another image onto this image at specific coordinates.
Drawing Operations
Drawing Setup
Before drawing, configure colors, stroke, and transparency:
Stroke Attributes:
width(numeric): Line thickness in pixels (default: 1)endCaps(string): Line end style - "butt", "round", "square" (default: "square")lineJoins(string): Corner style - "miter", "round", "bevel" (default: "miter")miterLimit(numeric): Limit for miter joins (default: 10)dashArray(array): Dash pattern [dash, gap, dash, gap...] (default: solid line)dashPhase(numeric): Offset for dash pattern (default: 0)
Shape Drawing
drawRect(x, y, width, height, [filled])
Draw a rectangle.
drawRoundRect(x, y, width, height, arcWidth, arcHeight, [filled])
Draw a rounded rectangle.
drawOval(x, y, width, height, [filled])
Draw an oval/ellipse.
drawBeveledRect(x, y, width, height, raised, [filled])
Draw a 3D beveled rectangle.
drawArc(x, y, width, height, startAngle, arcAngle, [filled])
Draw an arc or pie slice.
Line Drawing
drawLine(x1, y1, x2, y2)
Draw a straight line.
drawLines(xCoords, yCoords, isPolygon, [filled])
Draw connected lines or polygons.
Curve Drawing
drawCubicCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2)
Draw a cubic Bézier curve.
drawQuadraticCurve(ctrlx, ctrly, x1, y1, x2, y2)
Draw a quadratic Bézier curve.
Text Drawing
drawText(text, x, y, [fontConfig])
Draw text on the image.
Font config attributes:
font(string): Font family name (default: system default)size(numeric): Font size in points (default: 12)style(string): "plain", "bold", "italic", "bolditalic" (default: "plain")underline(boolean): Underline text (default: false)strikethrough(boolean): Strikethrough text (default: false)
Utility Drawing
clearRect(x, y, width, height)
Clear a rectangular region (makes it transparent).
Drawing Axis Transformations
Apply transformations to the drawing coordinate system:
rotateDrawingAxis(angle, x, y)
Rotate the drawing axis around a point.
translateDrawingAxis(x, y)
Translate (move) the drawing origin.
shearDrawingAxis(x, y)
Shear the drawing coordinate system.
Copying & Duplication
copy()
Create a duplicate of the entire image.
copy(x, y, width, height, dx, dy)
Copy a region within the image to another location.
Writing Images
write([path])
Write the image to disk.
Notes:
Parent directories are automatically created
Format is determined by file extension
File handles are properly closed (no Windows locking issues)
Information & Metadata
getWidth() / getHeight()
Get image dimensions.
info()
Get comprehensive image information.
getExifMetadata() / getIPTCMetadata()
Get metadata as a struct.
getExifTag(tag) / getIPTCTag(tag)
Get specific metadata tag value.
getBlob()
Get the image as a byte array.
getBufferedImage()
Get the underlying Java BufferedImage object.
Complete Chaining Example
The fluent API allows complex image processing pipelines:
Working with Multiple Images
Important Notes
File Handling
Images loaded from files are immediately read into memory - no file locking issues
Files can be deleted immediately after
ImageNew()orImageRead()write()automatically creates parent directories if they don't exist
Lazy Loading
Images are fully loaded upon creation - no lazy loading issues
Safe to use immediately after
ImageNew()without callinginfo()first
Color Format
Colors accept both names ("red", "blue", "navy") and hex codes ("#FF0000", "#0000FF")
See
BoxImage.COLORSmap for supported color names
Method Chaining
All transformation and drawing methods return
BoxImagefor chainingGetters (info, getWidth, getBlob, etc.) return their respective types and break the chain
Metadata
EXIF and IPTC metadata extracted automatically when loading from files
Metadata is preserved when copying images
Use
info()to access all metadata in a single struct
Related Documentation
Built-In Functions - Individual BIF documentation
Image Component - Tag-based approach
readme.md - Module overview and quick start
Last updated
Was this helpful?
