Image processing

Image composition

Use ImageContainer to set a background and canvas size, add elements, call combine(), and export the result. Later elements cover earlier ones. Element setters are not chainable.

Minimal example

For complete examples with images, text, watermarks, and a QR image, read the composition tutorial.

import com.ajaxjs.image.ImageContainer;
import com.ajaxjs.image.model.TextEmbedded;
import com.ajaxjs.image.model.constant.ImageFormat;
import com.ajaxjs.image.model.constant.ZoomMode;
import java.awt.Font;

ImageContainer container = new ImageContainer();
container.setOutputFormat(ImageFormat.PNG);
container.setBackgroundImage("background.jpg", ZoomMode.Origin, 0, 0);

TextEmbedded title = new TextEmbedded();
title.setText("Hello aj-image");
title.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 32));
title.setX(30);
title.setY(40);
container.addElement(title);

container.combine();
container.save("poster.png");

This example reads an existing background.jpg and saves poster.png. Replace the assets and text as needed; the output directory must already exist. Use PNG for transparency or whole-canvas rounded corners.

What can it do?

Current limitations

Behaviour to know

combine() publishes a result only after every drawing step succeeds. If a later composition fails, the previous successful result remains available. Blur uses a separate image, without modifying the source or accumulating across tiles.

Next: Image utilities and output · Home