Skip to main content

ReplaceCurrentImage

Replaces the current image with an image specified.

Syntax

expression.ReplaceCurrentImage(sImageUrl, Width, Height);

expression - A variable that represents a ApiPresentation class.

Parameters

NameRequired/OptionalData typeDefaultDescription
sImageUrlRequiredstringThe image source where the image to be inserted should be taken from (currently, only internet URL or Base64 encoded images are supported).
WidthRequiredEMUThe image width in English measure units.
HeightRequiredEMUThe image height in English measure units.

Returns

This method doesn't return any data.

Example

Swap an image for a different one in a presentation.

// How do I replace an image with another image in a presentation?

// Replace the selected image by loading a new one from a URL.

const presentation = Api.GetPresentation();
const slide = presentation.GetSlideByIndex(0);
slide.RemoveAllObjects();

const url1 = 'https://static.onlyoffice.com/assets/docs/samples/img/presentation_sky.png';
const url2 = 'https://static.onlyoffice.com/assets/docs/samples/img/onlyoffice_logo.png';

const drawing = Api.CreateImage(url1, 300 * 36000, 150 * 36000);
slide.AddObject(drawing);
drawing.Select();
presentation.ReplaceCurrentImage(url2, 60 * 36000, 60 * 36000);