Fastimage v1.0.0-rc1 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.

Link to this section Summary

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 image_type() View Source
image_type() :: :bmp | :gif | :jpeg | :png
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

Link to this function info(source, opts \\ []) View Source

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

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

Options

  • :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.

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 info!(source, opts \\ []) View Source

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

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

Options - see info/1

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 size(source, opts \\ []) View Source

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

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

Options

  • :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.

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 size!(source, opts \\ []) View Source

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

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

Options - see size/1

Example

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

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

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

Options

  • :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.

Example

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

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

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

Options - see type/1

Example

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