# `Ltix.DeepLinking.ContentItem.Image`
[🔗](https://github.com/DecoyLex/ltix/blob/main/lib/ltix/deep_linking/content_item/image.ex#L1)

An image content item for Deep Linking responses.

The platform renders the image directly using an HTML `img` tag.
For images that are part of a larger resource, consider using
`Ltix.DeepLinking.ContentItem.Link` with an `embed`.

## Examples

    iex> {:ok, image} = Ltix.DeepLinking.ContentItem.Image.new(
    ...>   url: "https://example.com/diagram.png",
    ...>   width: 800
    ...> )
    iex> Ltix.DeepLinking.ContentItem.to_map(image)
    %{"type" => "image", "url" => "https://example.com/diagram.png", "width" => 800}

## Options

* `:title` (`t:String.t/0`) - Title for the content item.

* `:text` (`t:String.t/0`) - Plain-text description.

* `:extensions` (`nil` | `t:map/0`) - Required. Vendor-specific extension properties. The default value is `%{}`.

* `:width` (`t:integer/0`) - Width of the image in pixels.

* `:url` (`t:String.t/0`) - Required. URL of the image.

* `:height` (`t:integer/0`) - Height of the image in pixels.

* `:icon` (`t:map/0`) - Icon or thumbnail for the image.

* `:thumbnail` (`t:map/0`) - Icon or thumbnail for the image.

# `t`

```elixir
@type t() :: %Ltix.DeepLinking.ContentItem.Image{
  extensions: nil | %{optional(binary() | atom()) =&gt; any()},
  height: nil | integer(),
  icon:
    nil
    | %{
        optional(:width) =&gt; integer(),
        :url =&gt; binary(),
        optional(:height) =&gt; integer()
      },
  text: nil | binary(),
  thumbnail:
    nil
    | %{
        optional(:width) =&gt; integer(),
        :url =&gt; binary(),
        optional(:height) =&gt; integer()
      },
  title: nil | binary(),
  url: binary(),
  width: nil | integer()
}
```

# `new`

```elixir
@spec new(keyword() | map()) :: {:ok, t()} | {:error, Exception.t()}
```

Create a new image content item.

Takes the module's options as a keyword list or map, and nested options such as
`icon` may also be keyword lists. Unknown or invalid options return an
`Ltix.Errors.Invalid.InvalidField` error.

## Examples

    iex> {:ok, image} = Ltix.DeepLinking.ContentItem.Image.new(url: "https://example.com/photo.png")
    iex> image.url
    "https://example.com/photo.png"

    iex> {:error, error} = Ltix.DeepLinking.ContentItem.Image.new([])
    iex> Exception.message(error)
    "Ltix.DeepLinking.ContentItem.Image field :url is required [DL §3.5]"

# `new!`

```elixir
@spec new!(keyword() | map()) :: t()
```

Same as `new/1` but raises on error.

## Examples

    iex> Ltix.DeepLinking.ContentItem.Image.new!(url: "https://example.com/photo.png").url
    "https://example.com/photo.png"

---

*Consult [api-reference.md](api-reference.md) for complete listing*
