View Source Eakins (eakins v0.0.1)

Eakins is a simple library that allows you to store image urls in your ecto schemas.

how-it-works

How it works

Eakins relies on having a known storage url embedded in your schema. This url is then used to create a display url that takes advantage of an image resizing proxy to show the image at the correct size and aspect ratio. Because an image proxy is used, changing your image sizes and aspects can be done at any time, and won't require you to go through all your images via a job queueuing system.

integrating-it-into-your-schemas

Integrating it into your schemas

To use Eakins with a schema, that schema must have a column with a :map datatype and a version column with an :integer data type. Then, use Eakins.Schema in your schema module and declare either an image_map or image_list field

defmodule UserSchema do
  use Ecto.Schema
  use Eakins.Schema

  schema "users" do
    field :first_name, :string
    field :last_name, :name
    image_map :avatars
  end
end

Your schema is now has an avatar image map, where you can store multiple images under different keys. See Eakins.Schema for more information on what you can do with the field and see Eakins.Image.Display for how to generate URLs with the field's value.

Link to this section Summary

Types

An aspect ratio

an alias for an aspect ratio

A height in pixels

The gravity of an image. When resizing, the image's gravity holds it to that position.

The height of an image in pixels

The index of an image in an image list

The name of an image in an image map

The size of an image either via a named size or in pixels

Link to this section Types

@type aspect() :: aspect_alias() | {pos_integer(), pos_integer()}

An aspect ratio

@type aspect_alias() :: :square

an alias for an aspect ratio

@type custom_height() :: pos_integer()

A height in pixels

@type gravity() :: String.t()

The gravity of an image. When resizing, the image's gravity holds it to that position.

@type height() :: pos_integer()

The height of an image in pixels

@type image() :: Eakins.Image.Stored.t()
@type index() :: integer()

The index of an image in an image list

@type key() :: index() | name()
@type name() :: String.t() | atom()

The name of an image in an image map

@type named_size() ::
  :tiny
  | :small
  | :medium
  | :large
  | :x_large
  | :avatar_small
  | :avatar_medium
  | :avatar_large
@type size() :: named_size() | custom_height()

The size of an image either via a named size or in pixels