diff --git a/exact/exact/annotations/static/annotations/js/exact-image-viewer.js b/exact/exact/annotations/static/annotations/js/exact-image-viewer.js index 589d72b0..74b1a486 100644 --- a/exact/exact/annotations/static/annotations/js/exact-image-viewer.js +++ b/exact/exact/annotations/static/annotations/js/exact-image-viewer.js @@ -609,6 +609,18 @@ class EXACTViewer { }); viewer.buttons.buttons.push(showNavigationButton); viewer.buttons.element.appendChild(showNavigationButton.element); + + let screenshotButton = new OpenSeadragon.Button({ + tooltip: 'Download screenshot of current view', + name: "Screenshot", + srcRest: viewer.prefixUrl + `screenshot.svg`, + srcGroup: viewer.prefixUrl + `screenshot.svg`, + srcHover: viewer.prefixUrl + `screenshot_hover.svg`, + srcDown: viewer.prefixUrl + `screenshot.svg`, + onClick: this.takeScreenshot.bind(this), + }); + viewer.buttons.buttons.push(screenshotButton); + viewer.buttons.element.appendChild(screenshotButton.element); } handleKeyUp(event) { @@ -665,6 +677,33 @@ class EXACTViewer { } } + takeScreenshot() { + const osdCanvas = this.viewer.drawer.canvas; + const overlayCanvas = document.getElementById('osd-overlaycanvas'); + + const width = osdCanvas.width; + const height = osdCanvas.height; + + const composite = document.createElement('canvas'); + composite.width = width; + composite.height = height; + const ctx = composite.getContext('2d'); + + ctx.drawImage(osdCanvas, 0, 0); + if (overlayCanvas) { + ctx.drawImage(overlayCanvas, 0, 0); + } + + const imageName = (this.imageInformation && this.imageInformation.name) + ? this.imageInformation.name.replace(/\.[^.]+$/, '') + : 'screenshot'; + + const link = document.createElement('a'); + link.download = imageName + '_screenshot.png'; + link.href = composite.toDataURL('image/png'); + link.click(); + } + finishAnnotation() { return; } diff --git a/exact/exact/annotations/static/images/screenshot.svg b/exact/exact/annotations/static/images/screenshot.svg new file mode 100644 index 00000000..b65e1b22 --- /dev/null +++ b/exact/exact/annotations/static/images/screenshot.svg @@ -0,0 +1,57 @@ + + diff --git a/exact/exact/annotations/static/images/screenshot_hover.svg b/exact/exact/annotations/static/images/screenshot_hover.svg new file mode 100644 index 00000000..c783a044 --- /dev/null +++ b/exact/exact/annotations/static/images/screenshot_hover.svg @@ -0,0 +1,57 @@ + + diff --git a/exact/exact/annotations/templates/annotations/annotate.html b/exact/exact/annotations/templates/annotations/annotate.html index 740b8a5b..75625b25 100644 --- a/exact/exact/annotations/templates/annotations/annotate.html +++ b/exact/exact/annotations/templates/annotations/annotate.html @@ -860,8 +860,8 @@