# ContentImageById()

Returns an `img` tag in which the `src` attribute is the path to an image from Content Builder. The img tag includes the title and alt information for the selected image, a `border` attribute set to `0`, and a `thid` attribute that contains an ID for the image.

This function only works with images in Content Builder. It doesn’t work with image blocks.

## Availability

<table>
  <tr>
    <td>Marketing Cloud Engagement</td>
    <td>✅ Yes</td>
  </tr>
  <tr>
    <td>Marketing Cloud Next</td>
    <td>❌ No</td>
  </tr>
</table>

## Syntax

```
ContentImageById(imageExternalId, defaultImageExternalId)
```

The `ContentImageById()` function has two parameters.

- `imageExternalId` (string): Required. The ID of an image in Content Builder.
- `defaultImageExternalId` (string): Required. The ID of a fallback image in Content Builder. The function uses this image if it can’t find the image that you specified in the `imageExternalKey` parameter.

## Usage

To use this function, pass it the ID of an image from Content Builder. You can optionally specify a default image to use if the function is unable to find the first image.

```
%%= ContentImageById(1237458, 1129480) =%%
```

If the function finds the image that you specified in the first parameter, it returns an `<img>` tag that refers to that image.

```
<img title="Logo" alt="Logo" src="https://image.s1.sfmc-content.com/lib/fef2120002460d/m/1/1bf72acc-dddf-4162-91b2-8d975059e0a5.png" border="0" thid="1237458">
```

If the function doesn’t find the specified image, it returns an `<img>` tag that refers to the image that you specified in the second parameter.

```
<img title="Default" alt="Default" src="https://image.s1.sfmc-content.com/lib/fef2120002460d/m/1/6b0374ed-b817-481b-8601-6bace4fabd3d.png" border="0" thid="1129480">
```

If you only want the URL of the image, use the `RegExMatch()` function to obtain the value of the `src` parameter.

```
%%[
  Var @regEx, @contentImage, @contentImageSrc
  Set @regEx = '(?<=\bsrc=")[^"]*'
  Set @contentImage = ContentImageById(1237458, 1129480)
  Set @contentImageSrc = RegExMatch(@contentImage, @regEx, 0)
]%%

Image URL: %%=v(@contentImageSrc)=%%
```

The function outputs the path to the image file.

```
Image URL: https://image.s1.sfmc-content.com/lib/fef2120002460d/m/1/1bf72acc-dddf-4162-91b2-8d975059e0a5.png
```
