StbImage (stb_image v0.1.0) View Source

Documentation for StbImage.

Link to this section Summary

Functions

Decode image from a given file

Decode image from a given file

Decode image from a given file

Decode image from buffer in memory

Decode image from buffer in memory

Decode image from buffer in memory

Link to this section Functions

Decode image from a given file

  • filename. Path to the image.

Example

{:ok, img, shape, type} = StbImage.from_file("/path/to/image")
{h, w, c} = shape
Link to this function

from_file(filename, desired_channels)

View Source

Decode image from a given file

  • filename. Path to the image.
  • desired_channels. 0 for auto-detection. Otherwise, the number of desired channels.

Example

# if you know the image is a 4-channel image and auto-detection failed
{:ok, img, shape, type} = StbImage.from_file("/path/to/image", 4)
{h, w, c} = shape
Link to this function

from_file(filename, desired_channels, type)

View Source

Decode image from a given file

  • filename. Path to the image.
  • desired_channels. 0 for auto-detection. Otherwise, the number of desired channels.
  • type. Specify format for each channel. :u8, :u16 or :f32.

Example

# Use 0 for auto-detecting number of channels
# but specify each channel is in float (32-bit)
{:ok, img, shape, type} = StbImage.from_file("/path/to/image", 0, :f32)
{h, w, c} = shape

Decode image from buffer in memory

  • buffer. Buffered raw file data in memory.

Example

# image buffer from a file or perhaps download from Internet
{:ok, buffer} = File.read("/path/to/image")
# decode the image from memory
{:ok, img, shape, type} = StbImage.from_memory(buffer)
{h, w, c} = shape
Link to this function

from_memory(buffer, desired_channels)

View Source

Decode image from buffer in memory

  • buffer. Buffered raw file data in memory.
  • desired_channels. 0 for auto-detection. Otherwise, the number of desired channels.

Example

# image buffer from a file or perhaps download from Internet
{:ok, buffer} = File.read("/path/to/image")
# decode the image from memory
# and specify it is a 4-channel image
{:ok, img, shape, type} = StbImage.from_memory(buffer, 4)
{h, w, c} = shape
Link to this function

from_memory(buffer, desired_channels, type)

View Source

Decode image from buffer in memory

  • buffer. Buffered raw file data in memory.
  • desired_channels. 0 for auto-detection. Otherwise, the number of desired channels.
  • type. Specify format for each channel. :u8, :u16 or :f32.

Example

# image buffer from a file or perhaps download from Internet
{:ok, buffer} = File.read("/path/to/image")
# decode the image from memory
# and specify it is a 3-channel image and each channel is in uint8_t
{:ok, img, shape, type} = StbImage.from_memory(buffer, 3, :u8)
{h, w, c} = shape