Getting Started

Getting started guide for image manipulation in BoxLang.

This guide will help you get up and running with image manipulation in BoxLang.

Table of Contents

Creating Images

There are several ways to create or load images in BoxLang:

From a File Path

// Using ImageRead()
img = ImageRead("path/to/image.jpg");

// Using ImageNew() - recommended
img = ImageNew("path/to/image.jpg");

From a URL

Create a Blank Canvas

From Base64 String

From Java BufferedImage

Reading Images

ImageRead() vs ImageNew()

Both functions read images, but ImageNew() is more versatile:

Supported Source Types

Basic Operations

Get Image Information

Check Image Properties

Get Supported Formats

Method Chaining

One of the most powerful features is method chaining with BoxImage:

Traditional BIF Approach

Why Method Chaining?

Benefits:

  1. Cleaner Code - More readable and concise

  2. Less Variables - No need to store intermediate results

  3. Natural Flow - Operations flow from left to right, top to bottom

  4. IDE Support - Better autocomplete and IntelliSense

  5. Immutable Operations - Each method returns the modified image

Mixing Approaches

You can mix BIF and member function syntax:

Saving Images

Write to File

Convert to Base64

Get as Byte Array

Get Java BufferedImage

Working with BoxImage

The BoxImage class is a fluent wrapper that makes image manipulation intuitive and powerful.

Creating BoxImage Instances

BoxImage is Mutable and Chainable

Copying Images

Complete Example

Quick Reference

Essential BIFs

Function
Purpose
Example

ImageNew()

Create/load image

ImageNew("photo.jpg")

ImageRead()

Load from file

ImageRead("photo.jpg")

ImageWrite()

Save to file

ImageWrite(img, "out.jpg")

ImageInfo()

Get image details

ImageInfo(img)

ImageGetWidth()

Get width

ImageGetWidth(img)

ImageGetHeight()

Get height

ImageGetHeight(img)

IsImage()

Check if image

IsImage(img)

IsImageFile()

Check if file is image

IsImageFile("photo.jpg")

Essential Member Functions

Next Steps

Now that you understand the basics, explore more advanced topics:

Last updated

Was this helpful?