Sidebar

Home



Expressions V4


Tutorials

How-To

Reference

  Lexical basics
  Type system
  Variables and assignment
  Operators
  Expression rules
  Control flow
  Functions
  Built-in functions
   None and NaN
   Arithmetic
   Algebra
   Logarithmic and Exponential
   Trigonometric
   Rounding and Centering
   Strings
   Output, Formatting, Clipboard, and Errors
   Dialog Functions
   Platform and Paths
  Methods and properties
  Built-in methods
   Common Value Methods
   Number Methods
   String Basic Methods
   String Slice Methods
   String Parsing Methods
   String Formatting Methods
   String Regex Methods
   String Trim and Case Methods
  Objects
  Built-in objects
   Global objects
    settings
    controller
    session
    python
   Collections
    array
    map
    bytes
   File Format I/O
    image_data
    image_stream
   Utils
    crypto
    timer
   Comm
    serial
   Dialogs
    file_open
    file_save
    msg_ok
    msg_ok_cancel
    msg_yes_no
    msg_password
   GUI objects
    window
    panel
    group
    splitpanel
    label
    textbutton
    drawablebutton
    togglebutton
    togglegroup
    textinput
    textedit
    numinput
    slider
    combobox
    listbox
    progressbar
    led
    separator
    menu
    image
    snake
  Classes and user-defined objects
  Include system
  Error model
  Execution model and sessions
  Host integration
  Limits and performance
  Formal reference
  Glossary

Cookbook

exprv4:reference:objects:image_data

image_data

`image_data` stores one static image in memory. It can load an image file, create an image from raw bytes, expose image metadata, and save supported image formats.

Constructor

image_data()

Creates an empty image object.

img = image_data();
print(img.valid);       // false

Properties

Property Type Description
`valid` boolean `true` when the object contains a valid image.
`width` number Image width in pixels.
`height` number Image height in pixels.
`channels` number Number of color channels in the raw image data.
`format` string Source image format, such as `png`, `jpeg`, `gif`, `webp`, `svg`, `bmp`, or `unknown`.
`data_size` number Size of the raw image data in bytes.
`error` string Last image error message.
`data` bytes Raw image bytes as a `bytes` object.
img = image_data().load("picture.png");
print(img.width);
print(img.height);

Common Object Methods

to_string()

Returns a display string for the object.

Item Description
Syntax `value.to_string()`
Arguments none
Returns string

Example:

text = value.to_string();

clone()

Returns a new image_data object with a separate copy of the image.

Item Description
Syntax `image_data.clone()`
Arguments none
Returns image_data object

Example:

img = image_data().load("picture.png");
copy = img.clone();

Methods

load(filePath)

Loads an image from `filePath` and returns the image object.

Argument Type Description
`filePath` string Path to an image file. Profile paths are resolved by the host application.

Returns: image_data object.

Example:

img = image_data().load("images/logo.png");
if (img.valid)
{
    print(img.width, " x ", img.height);
}
else
{
    print(img.error);
}

save(filePath)

Saves the image. The output format is selected from the file extension.

Argument Type Description
`filePath` string Output file path.

Returns: boolean-style number.

Supported save extensions:

Extension Format
`.png` PNG
`.jpg`, `.jpeg` JPEG
`.webp` WebP

Example:

img = image_data().load("input.png");
ok = img.save("output.webp");

clear()

Clears the image.

Item Description
Syntax `image_data.clear()`
Arguments none
Returns image_data object

Example:

img.clear();
print(img.valid);       // false

create(width, height, channels, data)

Creates an image from raw bytes.

Argument Type Description
`width` number Image width in pixels.
`height` number Image height in pixels.
`channels` number Number of channels per pixel.
`data` bytes A `bytes` object containing exactly `width * height * channels` bytes.

Returns: image_data object.

Example:

raw = bytes();
raw.add_u8(255); raw.add_u8(0); raw.add_u8(0);
img = image_data().create(1, 1, 3, raw);
img.save("red.png");

create(width, height, channels, data, format)

Creates an image from raw bytes and specifies the byte layout.

Argument Type Description
`width` number Image width in pixels.
`height` number Image height in pixels.
`channels` number Number of channels per pixel.
`data` bytes Raw image bytes.
`format` string Byte layout name.

Returns: image_data object.

Supported `format` values:

Format Description
`gray` Grayscale bytes.
`rgb` Red, green, blue order.
`rgba` Red, green, blue, alpha order.
`bgr` Blue, green, red order; converted to RGB.
`bgra` Blue, green, red, alpha order; converted to RGBA.

Example:

raw = bytes();
raw.add_u8(0); raw.add_u8(0); raw.add_u8(255);
img = image_data().create(1, 1, 3, raw, "bgr");

Previous: File Format I/O

Next: image_stream

exprv4/reference/objects/image_data.txt · Last modified: by andrej

Page Tools