
1. Style JSON Objects
Many image commands accept one or more style JSON objects. They all follow the same basic ideas:
- Colors are described with
color,alpha, etc. - Line styles (stroke) use
width+ color. - Fonts use
name,size,color, etc. - Some commands use nested styles like
"fill"and"line".
Below are the most common patterns.
1.1. Color Style ↑
A basic color style is used for fills, lines and fonts:
JSON style = JSON ( "color", "red", "alpha", 0.5 );
Supported keys:
color/rgb- Named colors:
"red","green","blue","black","white","gray","yellow","cyan","magenta","orange","teal","navy","purple", etc. - Hex RGB:
"FF0000","00FF00","0000FF","808080", etc. - Hex ARGB:
"80FF0000"(alpha + RGB).
- Named colors:
alpha(optional)- Number from
0.0to1.0. - Overrides any alpha in ARGB hex.
- Number from
tint(optional)- Number (e.g. Excel-style tinting; currently mainly stored, may be used later).
theme,indexed(optional)- Reserved for Excel-style palette/theme integration; preserved if present.
Examples:
JSON redFill = JSON ( "color" , "red" ); // solid red
JSON softGrey = JSON ( "color" , "808080" ; "alpha" ; 0.3 );
JSON named = JSON ( "color" , "orange" ); // mapped to hex internally
1.2. Line / Stroke Style ↑
Used for outlines (borders, lines, polygon edges, etc.).
JSON stroke = JSON ( "color", "black", "width", 2.0, "alpha", 0.8 );
ImageSetLineStyle ( img, stroke );
Supported keys:
color– stroke color (see Color Style above).alpha– opacity (0.0–1.0).width– stroke width in pixels.
Usage examples:
// Global line style for following commands:
ImageSetLineStyle ( img, JSON ( "color", "red", "width", 3 ) );
// Per-shape style:
ImageRect ( img, 100, 100, 200, 80,
JSON ( "color", "blue", "width", 1 ) );
1.3. Fill + Line Combined Style ↑
Some shape helpers (like pie segments, polygons, stars) use a combined style:
ImagePieSegment ( img,
400, 400, 100, 0, -90, 120,
JSON (
"fill", JSON ( "color", "red", "alpha", 0.8 ),
"line", JSON ( "color", "grey", "width", 1.0 )
)
);
Convention:
"fill"– JSON color style for fill. Shorthand: String containing "none", or any color value."line"– JSON line style for the outline. Shorthand: String containing "none", or any color value.
This allows you to set fill and border independently.
1.4. Font Style ↑
Font styles are used by ImageSetFont, ImageDrawText, ImageDrawTextBox, and ImageCornerBanner.
JSON fontStyle =
JSON ( "name", "Chalkboard",
"size", 24,
"color", "blue",
"alpha", 1.0 );
ImageSetFont ( img, fontStyle );
Supported keys:
name– font family name (e.g."Helvetica","Arial","Chalkboard"). Skia will try to match this using the platform font manager.size– font size in points/pixels (depending on rendering DPI).color– text color.alpha– opacity (0.0–1.0).- (internally) bold/italic/strike can be derived from markdown or future keys.
Note: Font style set by ImageSetFont are used globaly in all font drawing commands until next ImageSetFont. The individual drawing commands can override this by having the font-style set in the styleOptions parameter for that command. It does not affect the font style for the next drawing command. Such styleOptions given in the font-drawing commands can override one or more properties of the currently selected font, to example size, style, color or name of font.
Examples:
ImageSetFont ( img, JSON ( "name", "Helvetica", "size", 18, "color", "black" ) );
ImageDrawText ( img, 100, 200, "Hello ACF!", JSON ( "color", "red" ) );
1.5. TextBox / Paragraph Style ↑
ImageDrawTextBox and ImageCornerBanner can use extra layout-related keys in their style:
Common keys:
align(optional) – horizontal alignment inside the box:"left"(default),"center","right".
valign(optional) – vertical alignment:"top"(default),"middle".
size(optional) – base font size.color- Fill color for the box, can be set tononeif no fill wanted.rotate– (optional) rotation in degrees.lead– (optional) additional lead between lines.border- (optional) draw border around the text box. Can be an object describing the border line style, or an array of such objects for multiple borders.pos-outset(default),insetorcenterdetermine the position of the border. Center and inset may overlay the textbox inner edges. outset will expand the textbox perimeter.- Other linestyle options for the border, like
color,widthandalpha
corners– (optional) if border is specified, make them rounded. See description of this tag in theImageRectcommand.
Example for a centered corner banner:
JSON bannerStyle =
JSON ( "size", 24,
"color", "red",
"valign", "middle" );
ImageCornerBanner ( img,
50, 55, "tr",
"SPECIAL\nOFFER",
bannerStyle );
Example for a centered textbox:
JSON boxStyle =
JSON ( "color", "black",
"align", "center",
"valign", "middle" );
ImageDrawTextBox ( img,
100, 300, 300, 100,
"Centered text\nin a box",
boxStyle );
1.6. ImageRect Style ↑
Those use the same style as described in "Fill + Line Combined Style" above. In addition, you can specify rounded corners in this way:
ImageRect ( img,
400, 400, 100, 200,
JSON (
"fill", JSON ( "color", "red", "alpha", 0.8 ),
"line", JSON ( "color", "grey", "width", 1.0 ),
"corners", "rounded" // default radius of 8.
)
);
The "corners" tag is optional, and it can have those alternative versions: (Note: Setting a radius to Zero makes no rounding).
"corners", 16 // all four corners, radius 16
// or for individual radii (Top Left, Top Right, Bottom Left, Bottom Right).
"corners", JSON ( "tl", 20, "tr", 16, "bl", 8, "br", 4)
// or for one corner have a different rounding than the rest.
"corners", JSON ( "radius", 20, "tl", 16)
// or only the top left rounded
"corners", JSON ("tl",20)
The Corners key can also be used on text-boxes having borders.
1.7. Background Style (NewImage) ↑
The optional third parameter to NewImage is also a style JSON. It controls the initial background fill or background image:
// Solid white background
JSON img = NewImage ( 800, 600,
JSON ( "color", "white", "alpha", 1.0 ) );
// Background from container variable :bilde
JSON img2 = NewImage ( 800, 600,
JSON ( "image", ":bilde", "alpha", 0.25 ) );
Supported keys:
color– background color.alpha– opacity.image– image source:":varName"– placeholder referencing an ACF variable (container or string).- or a file path string.
- Supported image types are: SVG, PNG, JPG, BMP, TIFF
options"fit","stretch","tile"for how the background image is placed. "fit" (default) will scale the image to match the width if the created image, keeping aspect ratio. If the image becomes too high, the width is reduced. Too low image will leave empty (transparent) space in the bottom of the image. Using color key in addition will color that empty space.dpiTarget DPI for the image, default 72.icc_profilename of ICC profile for TIFF format, defining the colorspace used for CMYK colors). The following names are built in profiles.eciCMYK_v2Default ICC profile.PSOcoated_v3PSOuncoated_v3_FOGRA52icc_profile_pathCan be specified if none of the above fits. Posix path to an external ".icc" file.
