View Source Imgproxy (imgproxy v3.0.2)

Imgproxy generates urls for use with an imgproxy server.

Summary

Types

A number of pixels to be used as a dimension.

Provide type and enlarge configuration arguments to a resize option.

t()

Functions

Crop an image to the given width and height.

Generate a new Imgproxy.t/0 struct for the given image source URL to fetch the Info Endpoint.

Generate a new Imgproxy.t/0 struct for the given image source URL.

Resize an image to the given width and height.

Set the file extension (which will produce an image of that type).

Generate an imgproxy URL.

Types

@type dimension() :: float() | integer() | String.t()

A number of pixels to be used as a dimension.

@type resize_opts() :: [type: String.t(), enlarge: boolean()]

Provide type and enlarge configuration arguments to a resize option.

@type t() :: %Imgproxy{
  endpoint: String.t(),
  extension: nil | String.t(),
  key: nil | String.t(),
  options: keyword(list()),
  prefix: nil | String.t(),
  salt: nil | String.t(),
  source_url: nil | String.t()
}

Functions

Link to this function

add_option(img, name, args)

View Source
@spec add_option(t(), atom(), list()) :: t()

Add a formatting option to the Imgproxy.t/0.

For instance, to add the padding option with a 10px padding on all sides, you can use:

iex> img = Imgproxy.new("http://example.com/image.jpg")
iex> Imgproxy.add_option(img, :padding, [10, 10, 10, 10]) |> to_string()
"https://imgcdn.example.com/insecure/padding:10:10:10:10/aHR0cDovL2V4YW1wbGUuY29tL2ltYWdlLmpwZw"
Link to this function

crop(img, width, height, gravity \\ "ce:0:0")

View Source
@spec crop(t(), dimension(), dimension(), String.t()) :: t()

Crop an image to the given width and height.

Accepts an optional gravity parameter, by default it is "ce:0:0" for center gravity with no offset.

@spec info_new(String.t()) :: t()

Generate a new Imgproxy.t/0 struct for the given image source URL to fetch the Info Endpoint.

@spec new(String.t()) :: t()

Generate a new Imgproxy.t/0 struct for the given image source URL.

Link to this function

resize(img, width, height, opts \\ [])

View Source
@spec resize(t(), dimension(), dimension(), resize_opts()) :: t()

Resize an image to the given width and height.

Options include:

  • type: "fit" (default), "fill", or "auto"
  • enlarge: enlarge if necessary (false by default)
Link to this function

set_extension(img, extension)

View Source
@spec set_extension(t(), String.t()) :: t()

Set the file extension (which will produce an image of that type).

For instance, setting the extension to "png" will result in a PNG being created:

iex> img = Imgproxy.new("http://example.com/image.jpg")
iex> Imgproxy.set_extension(img, "png") |> to_string()
"https://imgcdn.example.com/insecure/aHR0cDovL2V4YW1wbGUuY29tL2ltYWdlLmpwZw.png"
Link to this function

set_gravity(img, type, xoffset \\ 0, yoffset \\ 0)

View Source
@spec set_gravity(t(), atom(), dimension(), dimension()) :: t()

Set the gravity option.

@spec to_string(t()) :: String.t()

Generate an imgproxy URL.

Example

iex> Imgproxy.to_string(Imgproxy.new("https://placekitten.com/200/300"))
"https://imgcdn.example.com/insecure/aHR0cHM6Ly9wbGFjZWtpdHRlbi5jb20vMjAwLzMwMA"