---
title: Dynamic Image Swap
type: plugins
category: Visualization
cat: visualization
order: 220
meta_title: Dynamic Image Swap
meta_description: Changes active image based on conditions
![]()
!!! note
For information about modifying this plugin or creating your own custom plugins, see Customize and Build Your Own Plugins.
For general plugin information, see [Plugins for projects](/guide/plugins) and [Plugin FAQ](faq).
This plugin dynamically adds an image element to the bottom of the annotation interface and updates that image based on which class label is clicked:

It works as follows:
images that maps label names (like "Addressee" or "Signature") to specific image file URLs based on a root path.img_uniq).<img> element with that ID..lsf-main-view__annotation) and appends the new image element to the end of it.LSI.annotation.names.get("label").children..lsf-label_clickable) and attaches a click event listener to each one.images mapping. It then sets the src attribute of the image element to that URL. If no matching image exists, the src might be empty.This plugin will work as-is with the demo check images. For your own purposes, you will want host images that Label Studio can access.
/**
* Display different example check images at the bottom of the layout
* depending on the class label selected
*/
const IMG_ID = "img_uniq";
// Use your own keys and values here for label lookup and data objects to display
const imagesRoot = "/static/plugins/src/different-images-per-label/img";
const images = {
Addressee: `${imagesRoot}/demo-addressee.jpg`,
"Account number": `${imagesRoot}/demo-routing-number.png`,
"Routing number": `${imagesRoot}/demo-routing-number.png`,
Signature: `${imagesRoot}/demo-sign.jpg`,
Amount: `${imagesRoot}/demo-amount.jpg`,
Watermark: `${imagesRoot}/demo-watermark.png`,
Date: `${imagesRoot}/demo-date.png`,
Correction: `${imagesRoot}/demo-correction.jpg`,
};
function appendCheckImg() {
let imageEl = window[IMG_ID];
if (!imageEl) {
imageEl = document.createElement("img");
imageEl.id = IMG_ID;
const labelingInterface = document.querySelector(
".lsf-main-view__annotation",
);
if (labelingInterface) {
labelingInterface.insertAdjacentElement("beforeend", imageEl);
} else {
console.error("Labeling interface element not found.");
}
}
// `label` is an actual tag name from config
const labels = LSI.annotation.names.get("label").children;
// If you will have more Labels in a future adjust the logic
document.querySelectorAll(".lsf-label_clickable").forEach((lbl, index) =>
lbl.addEventListener("click", () => {
const src = images[labels[index].value];
// if there are no images with this key image will just have an empty src
imageEl.src = src;
}),
);
}
appendCheckImg();
<View>
<View>
<Image name="image" value="$image" maxHeight="300px" />
<Labels name="label" toName="image">
<Label value="Addressee" background="gray" maxUsages="1" />
<Label value="Account number" background="magenta" maxUsages="1" />
<Label value="Routing number" background="green" maxUsages="1" />
<Label value="Signature" background="red" maxUsages="1" />
<Label value="Amount" background="orange" maxUsages="2" />
<Label value="Watermark" background="purple" />
<Label value="Date" background="brown" maxUsages="1" />
<Label value="Correction" background="black" maxUsages="1" />
</Labels>
<Rectangle name="bbox" toName="image" strokeWidth="3" />
</View>
<View>
<Header value="Example" />
<Header value="(Please make a selection)" size="5" />
</View>
</View>
Related tags:
{
"data": {
"image": "/static/plugins/src/different-images-per-label/img/demo-sample.png"
}
}