View Source ImageRs (image_rs v0.3.1)
Summary
Functions
Adjust the contrast of this image.
Performs a Gaussian blur on this image.
Brighten the pixels of this image.
Return a cut-out of this image delimited by the bounding rectangle.
Encode this image as format.
Filters this image with the specified 3x3 kernel.
Flip this image horizontally
Flip this image vertically
Decode image from buffer in memory
Similar to from_binary/1 but raises on errors
Decode image from a given file
Similar to from_file/1 but raises on errors
Creates an ImageRs
from a Nx tensor.
Return a grayscale version of this image.
Hue rotate the supplied image.
Invert the colors of this image.
Create a new ImageRs
from given binary with corresponding parameters.
Resize this image using the specified filter algorithm.
Resize this image using the specified filter algorithm.
Resize this image using the specified filter algorithm.
Rotate this image 90 degrees clockwise.
Rotate this image 180 degrees clockwise.
Rotate this image 270 degrees clockwise.
Saves the buffer to a file at the path specified.
Saves the buffer to a file at the path specified in the specified format.
Get binary representation of pixels.
Converts an ImageRs
to a Nx tensor.
Performs an unsharpen mask on this image.
Types
@type output_format() ::
:png
| :jpeg
| :pnm
| :gif
| :ico
| :bmp
| :farbfeld
| :tga
| :exr
| :tiff
| :avif
| :qoi
| :webp
@type t() :: %ImageRs{ channels: non_neg_integer(), color_type: :l | :la | :rgb | :rgba | :unknown, dtype: :u8 | :u16 | :f32, height: non_neg_integer(), resource: reference(), shape: [non_neg_integer()], width: non_neg_integer() }
Functions
Adjust the contrast of this image.
contrast
is the amount to adjust the contrast by.
Negative values decrease the contrast and positive values increase the contrast.
Performs a Gaussian blur on this image.
sigma
is a measure of how much to blur by.
Brighten the pixels of this image.
value
is the amount to brighten each pixel by.
Negative values decrease the brightness and positive values increase it.
@spec crop( t(), non_neg_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer() ) :: {:ok, t()} | {:error, String.t()}
Return a cut-out of this image delimited by the bounding rectangle.
@spec encode_as(t(), output_format(), Keyword.t()) :: {:ok, binary()} | {:error, String.t()}
Encode this image as format.
Filters this image with the specified 3x3 kernel.
Flip this image horizontally
Flip this image vertically
Decode image from buffer in memory
- data. Image data in memory.
Example
# image buffer from a file or perhaps download from the Internet
{:ok, data} = File.read("/path/to/image")
# decode the image from memory
{:ok, image} = ImageRs.from_binary(data)
width = image.width
height = image.height
channels = image.channels
shape = image.shape
{^height, ^width, ^channels} = shape
color_type = image.color_type
type = image.type
Similar to from_binary/1 but raises on errors
Decode image from a given file
- filename. Path to the image.
Example
{:ok, image} = ImageRs.from_file("/path/to/image")
width = image.width
height = image.height
channels = image.channels
shape = image.shape
{^height, ^width, ^channels} = shape
color_type = image.color_type
type = image.type
Similar to from_file/1 but raises on errors
Creates an ImageRs
from a Nx tensor.
The tensor is expected to have the shape {h, w, c}
and one of the supported types (u8/u16/f32).
Return a grayscale version of this image.
Returns Luma images in most cases. However, for f32 images, this will return a grayscale Rgb/Rgba image instead.
Hue rotate the supplied image.
value
is the degrees to rotate each pixel by.
0 and 360 do nothing, the rest rotates by the given degree value.
just like the css webkit filter hue-rotate(180)
Invert the colors of this image.
@spec new( pos_integer(), pos_integer(), :l | :la | :rgb | :rgba, :u8 | :u16 | :f32, binary() ) :: {:ok, t()} | {:error, String.t()}
Create a new ImageRs
from given binary with corresponding parameters.
@spec resize( t(), non_neg_integer(), non_neg_integer(), :nearest | :triangle | :catmull_rom | :gaussian | :lanczos3 ) :: {:ok, t()} | {:error, String.t()}
Resize this image using the specified filter algorithm.
Returns a new image. Does not preserve aspect ratio.
height
and width
are the new image's dimensions.
resize_preserve_ratio(image, height, width, filter_type \\ :lanczos3)
View Source@spec resize_preserve_ratio( t(), non_neg_integer(), non_neg_integer(), :nearest | :triangle | :catmull_rom | :gaussian | :lanczos3 ) :: {:ok, t()} | {:error, String.t()}
Resize this image using the specified filter algorithm.
Returns a new image. The image's aspect ratio is preserved.
The image is scaled to the maximum possible size that fits within the bounds specified by width
and height
.
@spec resize_to_fill( t(), non_neg_integer(), non_neg_integer(), :nearest | :triangle | :catmull_rom | :gaussian | :lanczos3 ) :: {:ok, t()} | {:error, String.t()}
Resize this image using the specified filter algorithm.
Returns a new image. The image's aspect ratio is preserved.
The image is scaled to the maximum possible size that fits within the larger
(relative to aspect ratio) of the bounds specified by height
and width
,
then cropped to fit within the other bound.
Rotate this image 90 degrees clockwise.
Rotate this image 180 degrees clockwise.
Rotate this image 270 degrees clockwise.
Saves the buffer to a file at the path specified.
@spec save_with_format(t(), Path.t(), output_format()) :: :ok | {:error, String.t()}
Saves the buffer to a file at the path specified in the specified format.
Get binary representation of pixels.
Converts an ImageRs
to a Nx tensor.
It accepts the same options as Nx.from_binary/3
.
Performs an unsharpen mask on this image.
sigma
is the amount to blur the image by.
threshold
is a control of how much to sharpen.