ImageViewer constructor.
Required. HTML element or CSS selector.
Optionaloptions: Partial<ViewerOptions>Optional. Viewer options.
StaticfindGets the viewer instance using the host element or host element selector.
Root HTML element or its CSS selector
Image Viewer instance if found
Create at least one image layer which will be used for painting.
Remove and dispose image layer given by argument layerOrIndex.
Image layer or image layer index or image layer name.
Remove and dispose all image layers.
Call this method in order to apply changes in @see:toolbarLayout.
const viewer = new DsImageViewer(document.querySelector("#viewer"));
const toolbar = viewer.toolbar;
const toolbarLayout = viewer.toolbarLayout;
toolbar.addItem({
key: 'custom-action',
icon: { type: "svg", content: '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path style="fill: #205F78;" d="M20.25 12l-2.25 2.25 2.25 2.25-3.75 3.75-2.25-2.25-2.25 2.25-2.25-2.25-2.25 2.25-3.75-3.75 2.25-2.25-2.25-2.25 2.25-2.25-2.25-2.25 3.75-3.75 2.25 2.25 2.25-2.25 2.25 2.25 2.25-2.25 3.75 3.75-2.25 2.25 2.25 2.25z"></path></svg>' },
title: 'Custom action',
checked: false, enabled: false,
action: function () {
alert("Implement your action here.");
},
onUpdate: function (args) {
return {
enabled: true,
checked: false,
title: 'Custom action title'
}
}
});
toolbarLayout.viewer.default.splice(0, 0, "custom-action");
viewer.applyToolbarLayout();
Adds a plugin instance to the DsImageViewer. This method is now intended for internal and officially supported plugins only. Custom or third-party plugins are no longer supported starting from version 9.0. The plugin system remains available for internal use to provide optional viewer features, such as ImageFiltersPlugin, PageToolsPlugin, and PaintToolsPlugin. Attempting to register non-official plugins may lead to undefined behavior and is not supported by the product team.
The plugin instance
true if added successfully; otherwise false.
Add window keyboard listener.
Listener key.
Keyboard event handler.
Remove window keyboard listener.
Listener key.
Allows to configure the main toolbar layout.
The position where the buttons should be inserted. Use false or -1 to skip insertion. Undefined means the position will be determined automatically.
An array of button keys to be inserted.
Retrieves the point location from the pointer event provided by the 'event' parameter. The returned point is relative to the active canvas element.
DOM Pointer or Mouse event object.
Sets the cursor style for the image viewer
The cursor style to apply
Toggles between specified cursor and default style
Cursor style to apply, or false to reset
Load image data using given data url.
OptionaldestinationSize: SizeDefines needed image size
Display confirmation dialog.
OptionalconfirmationText: anyConfirmation text can be plain string or JSX.Element if you're using React.
Optionallevel: "error" | "info" | "warning"Optionaltitle: stringOptionalbuttons: ConfirmButton[]Removes a plugin instance from the DsImageViewer. This method remains available for internal and officially supported plugins only. Custom or third-party plugins are no longer supported starting from version 9.0.
Plugin id or plugin instance.
Show about dialog.
Finds a viewer plugin by its id.
Plugin id
Clear undo storage.
Execute a new command.
Instance of a command.
Create new empty image.
Optionaloptions: Partial<Size> & OpenParametersOptional. New image parameters.
Open Image document.
Image URL or it's binary data.
OptionalopenParameters: ImageFormatName | ImageFormatCode | OpenParametersImage format or image opening parameters object.
Use this method to close and release resources occupied by the DsImageViewer.
Trigger event.
Embedded or custom event name.
Optionalargs: Record<string, unknown>Arguments for event handler function.
Get unmodified current image data url.
Get current image data url.
Modify current image data url.
Displays a second toolbar specified by the toolbarKey argument.
The key identifying the specific second toolbar to show.
A Promise that resolves once the second toolbar is successfully displayed.
Hides the second toolbar. This method deactivates any active editor mode associated with the second toolbar and then hides the toolbar itself.
OptionaltoolbarKey: SecondToolbarTypeOptional. The key identifying the specific second toolbar to hide. If provided, only hides the specified toolbar if it exists.
A Promise that resolves once the second toolbar is successfully hidden.
Saves the Image document loaded in the Viewer to the local disk.
Optionaloptions: string | SaveOptionsOptional Destination file name or the save options, including the destination file name and other settings.
Optionaloriginal: booleanOptional Flag indicating whether to use the initial version of the image for save. Defaults to false.
// Example: Save the modified image without using specific options.
const viewer = DsImageViewer.findControl("#root");
viewer.save();
// Example: Save the modified image as "image.png".
const viewer = DsImageViewer.findControl("#root");
viewer.save({ fileName: "image.png" });
// Example: Download the original version of the image as "original_image.jpg".
const viewer = DsImageViewer.findControl("#root");
viewer.save({ fileName: "original_image.jpg", original: true });
Shows the message for the user.
Message title text
Additional details text, empty by default.
Message severity, default "info".
StaticLicenseGets or sets the license key.
Indicates whether the viewer has opened the image.
Gets the active image DPI adaptive natural size. This is the image size that will be used to display the image at 100%. The adaptiveNaturalSize property is used for the actual size calculations.
Gets the actual display size of the active image, including the active zoom value.
language - A property that retrieves the standardized language key based on the provided language option.
The language key is determined by the options.language setting.
Image layers. Used for painting.
Gets the active image natural size. The natural size is the image's width/height if drawn with nothing constraining its width/height, this is the number of CSS pixels wide the image will be.
The Open parameters that were used to open an image.
Command based undo state storage.
Gets a value indicating whether the image viewer can undo changes.
Gets a value indicating whether the image viewer can redo changes.
Gets current undo level index.
Gets total undo levels count.
Returns the current version of the DS Image viewer.
Gets total frames count for the active image. Applicable for TIFF, ICO images.
Image viewer event bus.
The event raised when the user changes the viewer theme.
Occurs immediately before the image opens.
The event indicating error.
The event raised when appearance image element changed.
Gets a value indicating whether the image animation has started.
Viewer options
Defines the layout of the toolbar. The full list of the viewer specific toolbar items:
'open', '$navigation', 'navigation-auto', '$split', 'zoom', '$fullscreen', 'save', 'about'
Gets or sets the active frame index. This is applicable for multi-frame images such as TIFF and ICO.
When setting this value, it will also be used as the initial frame index when opening a new image.
Gets or sets the current zoom settings
Document Solutions Image Viewer is a fast JavaScript based client-side Image Viewer that runs in all major browsers.
Note that DsImageViewer is the new name for GcImageViewer, with the same API.
During this transition period we are publishing both versions, but it is recommended that you switch to using DsImageViewer when possible.
Example