Blendend.Image (blendend v0.3.0)
View SourceImage loading functions for Blendend.
This module deals with image resources that can be used anywhere pixel data is needed: as sources for patterns, or passed directly to canvas blit calls.
Typical uses:
- create a tiling or transformed fill via
Blendend.Style.Pattern.create/1 - draw an image onto a canvas via
Blendend.Canvas.blit_image/4(or/6)
Summary
Functions
Returns a blurred copy of image using a Gaussian approximation.
Same as blur/2, but returns the blurred image or raises on failure.
Decodes a QOI binary into raw RGBA bytes for tests and diagnostics.
Loads an image from an in-memory binary.
Loads image data from a binary and converts it to A8 (alpha-only) using the given channel.
Loads an image from path.
Same as from_file/1, but returns the image directly.
Loads an image from path and converts it to an 8-bit mask using the given channel.
Same as from_file_a8/2, but raises on failure.
Returns the image size in pixels.
Same as size/1, but returns the {width, height} tuple directly.
Types
Functions
Returns a blurred copy of image using a Gaussian approximation.
sigma controls blur strength in pixels (roughly 3×sigma is the visible radius).
Supports PRGB32 and A8 images; other formats are converted to PRGB32 first.
Same as blur/2, but returns the blurred image or raises on failure.
@spec decode_qoi(binary()) :: {:ok, {pos_integer(), pos_integer(), binary()}} | {:error, term()}
Decodes a QOI binary into raw RGBA bytes for tests and diagnostics.
Returns {:ok, {width, height, data}} where data is a binary of
length width * height * 4 in RGBA byte order.
@spec decode_qoi!(binary()) :: {pos_integer(), pos_integer(), binary()}
Loads an image from an in-memory binary.
The binary is the raw image file contents.
On success, returns {:ok, image}.
On failure, returns {:error, reason}.
Loads image data from a binary and converts it to A8 (alpha-only) using the given channel.
Loads an image from path.
This reads the file in Elixir and lets the NIF decode the bytes. The file must be in a format blend2d understands (e.g. PNG, JPEG, BMP, QOI ).
On success, returns {:ok, image} where image is an opaque resource.
On failure, returns {:error, reason}.
Same as from_file/1, but returns the image directly.
On success, returns image.
On failure, raises Blendend.Error.
Loads an image from path and converts it to an 8-bit mask using the given channel.
Channel can be :red (default), :green, :blue, :alpha, or :luma.
Same as from_file_a8/2, but raises on failure.
@spec size(t()) :: {:ok, {non_neg_integer(), non_neg_integer()}} | {:error, term()}
Returns the image size in pixels.
On success, returns {:ok, {width, height}} where dimensions are in pixels.
On failure, returns {:error, reason}.
@spec size!(t()) :: {non_neg_integer(), non_neg_integer()}
Same as size/1, but returns the {width, height} tuple directly.
On success, returns {width, height}.
On failure, raises Blendend.Error.