Fastimage v1.0.0-rc4 Fastimage View Source

Fastimage finds the dimensions/size or file type of a remote url, local image file or a binary object given the url, file path or binary itself respectively.

It streams the smallest amount of data necessary to ascertain the file size.

Supports “.bmp”, “.gif”, “.jpeg”, “.webp” or “.png” image types only.

Link to this section Summary

Types

  • :stream_timeout - Applies to a url only. An override for the after :stream_timeout field in the Fastimage.Stream.Acc struct which in turn determines the timeout in the processing of the hackney stream. By default the @default_stream_timeout is used in Fastimage.Stream.Acc
t()

Functions

Returns a %Fastimage{} struct with information such as type and dimensions. Accepts a source as a url, binary object or file path

Returns a %Fastimage{} struct with information such as type and dimensions. Accepts a source as a url, binary object or file path

Returns the dimensions of the image. Accepts a source as a url, binary object or file path

Returns the dimensions of the image. Accepts a source as a url, binary object or file path

Returns the type of image. Accepts a source as a url, binary object or file path

Returns the type of image. Accepts a source as a url, binary object or file path

Link to this section Types

Link to this type fastimage_opts() View Source
fastimage_opts() :: [
  stream_timeout: non_neg_integer(),
  max_error_retries: non_neg_integer(),
  max_redirect_retries: non_neg_integer()
]
  • :stream_timeout - Applies to a url only. An override for the after :stream_timeout field in the Fastimage.Stream.Acc struct which in turn determines the timeout in the processing of the hackney stream. By default the @default_stream_timeout is used in Fastimage.Stream.Acc.

  • :max_error_retries - Applies to a url only. An override for the :max_error_retries field in the Fastimage.Stream.Acc struct which in turn determines the maximum number of retries that will be attempted before giving up and returning an error. By default the @default_max_error_retries is used in Fastimage.Stream.Acc.

  • :max_redirect_retries - Applies to a url only. An override for the :max_redirect_retries field in the Fastimage.Stream.Acc struct which in turn determines the maximum number of redirects that will be attempted before giving up and returning an error. By default the @default_max_redirect_retries is used in Fastimage.Stream.Acc.

Link to this type image_type() View Source
image_type() :: :bmp | :gif | :jpeg | :png | :webp
Link to this type source_type() View Source
source_type() :: :url | :file | :binary
Link to this type t() View Source
t() :: %Fastimage{
  dimensions: Fastimage.Dimensions.t(),
  image_type: image_type() | nil,
  source: binary() | nil,
  source_type: source_type() | nil
}

Link to this section Functions

Returns a %Fastimage{} struct with information such as type and dimensions. Accepts a source as a url, binary object or file path.

Example

iex> Fastimage.info!("https://raw.githubusercontent.com/stephenmoloney/fastimage/master/priv/test.jpg")
%Fastimage{
  dimensions: %Fastimage.Dimensions{height: 142, width: 283},
  image_type: :jpeg,
  source: "https://raw.githubusercontent.com/stephenmoloney/fastimage/master/priv/test.jpg",
  source_type: :url
}
Link to this function info(source, opts \\ []) View Source
info(binary(), fastimage_opts()) ::
  {:ok, Fastimage.t()} | {:error, Fastimage.Error.t()}

Returns a %Fastimage{} struct with information such as type and dimensions. Accepts a source as a url, binary object or file path.

Example

iex> Fastimage.info("https://raw.githubusercontent.com/stephenmoloney/fastimage/master/priv/test.jpg")
{:ok,
  %Fastimage{
   dimensions: %Fastimage.Dimensions{height: 142, width: 283},
   image_type: :jpeg,
   source: "https://raw.githubusercontent.com/stephenmoloney/fastimage/master/priv/test.jpg",
   source_type: :url
  }}
Link to this function size!(source, opts \\ []) View Source
size!(binary(), fastimage_opts()) :: Fastimage.Dimensions.t() | no_return()

Returns the dimensions of the image. Accepts a source as a url, binary object or file path.

Example

iex> Fastimage.size!("https://raw.githubusercontent.com/stephenmoloney/fastimage/master/priv/test.jpg")
%Fastimage.Dimensions{height: 142, width: 283}
Link to this function size(source, opts \\ []) View Source
size(binary(), fastimage_opts()) ::
  {:ok, Fastimage.Dimensions.t()} | {:error, Fastimage.Error.t()}

Returns the dimensions of the image. Accepts a source as a url, binary object or file path.

Example

iex> Fastimage.size("https://raw.githubusercontent.com/stephenmoloney/fastimage/master/priv/test.jpg")
{:ok, %Fastimage.Dimensions{height: 142, width: 283}}
Link to this function type!(source, opts \\ []) View Source
type!(binary(), fastimage_opts()) :: image_type() | no_return()

Returns the type of image. Accepts a source as a url, binary object or file path.

Example

iex> Fastimage.type!("https://raw.githubusercontent.com/stephenmoloney/fastimage/master/priv/test.jpg")
:jpeg
Link to this function type(source, opts \\ []) View Source
type(binary(), fastimage_opts()) ::
  {:ok, image_type()} | {:error, Fastimage.Error.t()}

Returns the type of image. Accepts a source as a url, binary object or file path.

Example

iex> Fastimage.type("https://raw.githubusercontent.com/stephenmoloney/fastimage/master/priv/test.jpg")
{:ok, :jpeg}