View Source ImageRs (image_rs v0.3.0)
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
Decode image from a given file
Return a grayscale version of this image.
Hue rotate the supplied image.
Invert the colors of this image.
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.
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
@spec adjust_contrast(ImageRs.DynamicImage.t(), float()) :: {:ok, ImageRs.DynamicImage.t()} | {:error, String.t()}
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.
@spec blur(ImageRs.DynamicImage.t(), float()) :: {:ok, ImageRs.DynamicImage.t()} | {:error, String.t()}
Performs a Gaussian blur on this image.
sigma is a measure of how much to blur by.
@spec brighten(ImageRs.DynamicImage.t(), integer()) :: {:ok, ImageRs.DynamicImage.t()} | {:error, String.t()}
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( ImageRs.DynamicImage.t(), non_neg_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer() ) :: {:ok, ImageRs.DynamicImage.t()} | {:error, String.t()}
Return a cut-out of this image delimited by the bounding rectangle.
@spec encode_as(ImageRs.DynamicImage.t(), output_format(), Keyword.t()) :: {:ok, ImageRs.DynamicImage.t()} | {:error, String.t()}
Encode this image as format.
@spec filter3x3( ImageRs.DynamicImage.t(), [number()] ) :: {:ok, ImageRs.DynamicImage.t()} | {:error, String.t()}
Filters this image with the specified 3x3 kernel.
@spec fliph(ImageRs.DynamicImage.t()) :: {:ok, ImageRs.DynamicImage.t()} | {:error, String.t()}
Flip this image horizontally
@spec flipv(ImageRs.DynamicImage.t()) :: {:ok, ImageRs.DynamicImage.t()} | {:error, String.t()}
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.DynamicImage.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
Decode image from a given file
- filename. Path to the image.
Example
{:ok, image} = ImageRs.DynamicImage.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
@spec grayscale(ImageRs.DynamicImage.t()) :: {:ok, ImageRs.DynamicImage.t()} | {:error, String.t()}
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.
@spec huerotate(ImageRs.DynamicImage.t(), integer()) :: {:ok, ImageRs.DynamicImage.t()} | {:error, String.t()}
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)
@spec invert(ImageRs.DynamicImage.t()) :: {:ok, ImageRs.DynamicImage.t()} | {:error, String.t()}
Invert the colors of this image.
@spec resize( ImageRs.DynamicImage.t(), non_neg_integer(), non_neg_integer(), :nearest | :triangle | :catmull_rom | :gaussian | :lanczos3 ) :: {:ok, ImageRs.DynamicImage.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( ImageRs.DynamicImage.t(), non_neg_integer(), non_neg_integer(), :nearest | :triangle | :catmull_rom | :gaussian | :lanczos3 ) :: {:ok, ImageRs.DynamicImage.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( ImageRs.DynamicImage.t(), non_neg_integer(), non_neg_integer(), :nearest | :triangle | :catmull_rom | :gaussian | :lanczos3 ) :: {:ok, ImageRs.DynamicImage.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.
@spec rotate90(ImageRs.DynamicImage.t()) :: {:ok, ImageRs.DynamicImage.t()} | {:error, String.t()}
Rotate this image 90 degrees clockwise.
@spec rotate180(ImageRs.DynamicImage.t()) :: {:ok, ImageRs.DynamicImage.t()} | {:error, String.t()}
Rotate this image 180 degrees clockwise.
@spec rotate270(ImageRs.DynamicImage.t()) :: {:ok, ImageRs.DynamicImage.t()} | {:error, String.t()}
Rotate this image 270 degrees clockwise.
@spec save(ImageRs.DynamicImage.t(), Path.t()) :: {:ok, ImageRs.DynamicImage.t()} | {:error, String.t()}
Saves the buffer to a file at the path specified.
@spec save_with_format(ImageRs.DynamicImage.t(), Path.t(), output_format()) :: {:ok, ImageRs.DynamicImage.t()} | {:error, String.t()}
Saves the buffer to a file at the path specified in the specified format.
@spec unsharpen(ImageRs.DynamicImage.t(), float(), integer()) :: {:ok, ImageRs.DynamicImage.t()} | {:error, String.t()}
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.