Occurs immediately before the image opens.
var viewer = new DsImageViewer('#root');
viewer.onBeforeOpen.register(function(args) {
alert("A new image will be opened,\n payload type(binary or URL): " + args.type +",\n payload(bytes or string): " + args.payload);
});
viewer.open('Test.png');
Gets a value indicating full screen mode.
Gets a value indicating whether the toolbar is hidden.
Indicates whether the viewer has opened the image.
var hasImageFlag = viewer.hasImage;
Gets a format type of the opened image.
Sets a format type of the opened image.
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.
Command based undo state storage.
const isUndoInProgress = viewer.undoStorage.undoInProgress;
Outermost viewer's host element containing the gc-viewer-host class.
Saves the Image document loaded in the Viewer to the local disk.
// 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 });
// Example: Save the modified image in PNG format.
const viewer = DsImageViewer.findControl("#root");
viewer.save({ convertToFormat: "image/png" });
// Example: Save the modified image with a custom file name and in JPEG format.
const viewer = DsImageViewer.findControl("#root");
viewer.save({ fileName: "custom_name", convertToFormat: "image/jpeg" });
Optional options: string | SaveOptionsThe save options, including the destination file name and other settings.
Optional original: booleanFlag indicating whether to use the initial version of the image for save. Defaults to false.
Call this method in order to apply changes in @see:toolbarLayout.
viewer.toolbarLayout.viewer.default = ["open", "save"];
viewer.applyToolbarLayout();
var viewer = new GcImageViewer(document.querySelector("#viewer"));
var toolbar = viewer.toolbar;
var 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();
Add window keyboard listener.
Used preliminarily by the plugin developers to configure the main toolbar layout.
// Apply a custom layout to insert "zoomIn" and "zoomOut" buttons at position 2 for the "PaintTools" plugin.
viewer.configurePluginMainToolbar(2, ["zoomIn", "zoomOut"]);
void
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.
Create at least one image layer which will be used for painting.
Finds a viewer plugin by its id.
// find imageFilters plugin:
var imageFilters = viewer.findPlugin("imageFilters");
// find pageTools plugin:
var pageTools = viewer.findPlugin("pageTools");
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
// Set rotate cursor during image rotation
viewer.setCursor('rotate');
// Set resize cursor when hovering over edges
viewer.setCursor('nwse-resize');
GlobalCursorType for all available cursor options
The cursor style to apply
Resets the cursor to default style
// Reset cursor when operation completes
viewer.resetCursor();
// Reset cursor on mouse leave
viewerElement.addEventListener('mouseleave', () => {
viewer.resetCursor();
});
Toggles between specified cursor and default style
// Toggle grab cursor during drag operations
viewer.toggleCursor(isDragging ? 'grab' : false);
// Toggle zoom cursor based on modifier key
document.addEventListener('keydown', (e) => {
if (e.ctrlKey) {
viewer.toggleCursor('zoom-in');
}
});
Cursor style to apply, or false to reset
Display confirmation dialog.
Optional confirmationText: string | ElementOptional level: "error" | "info" | "warning"Optional title: stringOptional buttons: ConfirmButton[]Remove and dispose image layer given by argument layerOrIndex.
Image layer or image layer index or image layer name.
Show a second toolbar specified by the toolbarKey argument.
// Show page tools bar.
viewer.showSecondToolbar("page-tools");
Sets of toggles sidebar's panels visibility
Optional show: booleanDefines the layout of the toolbar.
The full list of the viewer specific toolbar items:
'open', '$navigation', '$split', 'zoom', '$fullscreen', 'save', 'about'
// Customize the toolbar layout:
viewer.toolbarLayout.viewer.default = ["open", "$zoom", "$fullscreen", "save", "print", "about"];
viewer.applyToolbarLayout();
Readonly in17ni18next instance.
Interface describing the ImageViewer API, primarily utilized for control/plugin development purposes.