# Javascript: ImageCollection.addAnchoredAtLocation Method

> Inserts a new image which is anchored to the specified text position. It has the specified location relative to the paragraph it is anchored to and a textflow which is given through the insertionMode parameter. Anchored images are moved with the text.

- **Product:** TX Text Control .NET Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 28.0
- **Path:** TX Text Control .NET Server > Reference > JavaScript API > Javascript: ImageCollection.addAnchoredAtLocation Method
- **657 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/imagecollection/addanchoredatlocation-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/imagecollection/addanchoredatlocation-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/imagecollection/addanchoredatlocation-method/llms-full.txt

---

### Description

Inserts a new image which is anchored to the specified text position. It has the specified location relative to the paragraph it is anchored to and a textflow which is given through the insertionMode parameter. Anchored images are moved with the text.

### Syntax

```javascript
<void> ImageCollection.addAnchoredAtLocation(<string> imageData, <Point> location, <number> textPosition, <ImageInsertionMode> insertionMode, [<RequestImageCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| imageData | The base64 encoded image data. |
| location | Specifies the location, in twips, at which the image is to be inserted. This is a location relative to the top left corner either of a page or of a paragraph. |
| textPosition | Specifies the text position at which the image is to be inserted. If -1 is specified, the image is inserted at the current input position. |
| insertionMode | Specifies how the text flow is handled. |
| callback | Optional. The newly created image object is returned via this callback function. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `ImageCollection.addAnchoredAtLocation` in a practical document-editing workflow. It inserts a new image which is anchored to the specified text position. It has the specified location relative to the paragraph it is anchored to and a textflow which is given through the insertionMode parameter. Anchored images are moved with the text.

```javascript
function onTxError(error) {
    console.error("TX Text Control error:", error.msg);
    error.handled = true;
}

TXTextControl.images.addAnchoredAtLocation(
    "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAFgAH/qbPzWQAAAABJRU5ErkJggg==",
    { x: 1440, y: 720 },
    -1,
    TXTextControl.ImageInsertionMode.AsCharacter,
    function(image) {
        if (!image) {
            console.warn("No image was returned.");
            return;
        }
        
        console.log("add anchored at location result:", image);
    },
    onTxError
);
```

---

## Nearby

- **Previous:** [Javascript: ImageCollection.addAnchored Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/imagecollection/addanchored-method/llms-full.txt)
- **Next:** [Javascript: ImageCollection.addAtFixedPosition Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/imagecollection/addatfixedposition-method/llms-full.txt)
