This package is a client to generate URLs to Thumbor using Elixir language.
The package can be installed by adding thumbor_client
to your list of dependencies in mix.exs
:
def deps do
[
{:thumbor_client, "~> 0.4.0"}
]
end
iex> client = ThumborClient.client("my_secret_token")
iex> client.(%{image: "path/to/image.jpg", width: 500, height: 500})
"1_6x25QaeExcQVmtuNyrr_lOs-0=/500/500/path/to/image.jpg"
iex> client = ThumborClient.client()
iex> client.("%{image: "path/to/image.jpg", width: 500, height: 500})
"unsafe/500/500/path/to/image.jpg"
The method client("key")
is recommended if you will generate multiple images in same function.
If you prefer, you can call the method generate without this HOF.
iex> ThumborClient.generate(%{image: "image.jpg", width: 500, height: 500}, "my_secret_token")
# The last parameter is optional, if not exist should use unsafe mode
Option | Default Value | Description |
---|---|---|
trim: (bool) | false | Removes surrounding space in image using top-left pixel color unless specified otherwise |
meta: (bool) | false | Instead of get the image, get all meta data informations in image returning using json |
fit: (atom|nil) | nil | The fit argument specifies that the image should not be auto-cropped and auto-resized to be EXACTLY the specified size. Possible values: :fit_in, :adaptive_fit_in, :full_fit_in, :adaptive_full_fit_in |
width: (integer) | 0 | Final width of image |
height: (integer) | 0 | Final height of image |
flip: (bool) | false | Flip image horizontaly |
flop: (bool) | false | Flip image verticaly |
halign: (atom) | :center | Orientation to crop horizontaly. Possible values: :left , :center , :right |
valign: (atom) | :center | Orientation to crop verticaly. Possible values: :top , :center , :bottom |
smart: (bool) | false | Use Thumbor algorithms to crop using facial recognition process |
filters: (list) | [] | Adding filters to image. More details bellow |
image: (string) | nil | Path of image. Can be external. |
You can see a big list of filters in official Thumbor documentation. You must set a list of strings with values.
Examples of usage:
ThumborClient.generate(%{filters: ["brightness(40)"], width: 400, height: 300, path: "/path/image.jpg"})
ThumborClient.generate(%{filters: ["blur(40)"], width: 400, height: 300, path: "/path/image.jpg"})
ThumborClient.generate(%{filters: ["grayscale()"], width: 400, height: 300, path: "/path/image.jpg"})
ThumborClient.generate(%{filters: ["grayscale()", "rotate(90)", "saturate(20)"], width: 400, height: 300, path: "/path/image.jpg"})
The docs can be found at https://hexdocs.pm/thumbor_client.