add option to download images in different formats
This commit is contained in:
parent
eef7c52c7e
commit
d804f56152
@ -25,6 +25,9 @@ frontend:
|
|||||||
# Show the smallest screen indicator ? (with dotted lines) -- boolean
|
# Show the smallest screen indicator ? (with dotted lines) -- boolean
|
||||||
showSmallestScreenIndicator: true
|
showSmallestScreenIndicator: true
|
||||||
|
|
||||||
|
# Image download format, can be "png", "jpeg" (or "webp" -> only working on chrome) -- string
|
||||||
|
imageDownloadFormat: "png"
|
||||||
|
|
||||||
# Frontend performance tweaks
|
# Frontend performance tweaks
|
||||||
performance:
|
performance:
|
||||||
# Refresh frequency of the debug / info div (in Hz i.e. /s) -- number
|
# Refresh frequency of the debug / info div (in Hz i.e. /s) -- number
|
||||||
|
@ -48,6 +48,9 @@
|
|||||||
"showSmallestScreenIndicator": {
|
"showSmallestScreenIndicator": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"imageDownloadFormat": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"performance": {
|
"performance": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
@ -26,6 +26,7 @@ function startBackendServer(port) {
|
|||||||
console.log("Webserver & socketserver running on port:" + port);
|
console.log("Webserver & socketserver running on port:" + port);
|
||||||
|
|
||||||
const { accessToken, enableWebdav } = config.backend;
|
const { accessToken, enableWebdav } = config.backend;
|
||||||
|
const { imageDownloadFormat } = config.frontend;
|
||||||
|
|
||||||
app.get("/api/loadwhiteboard", function (req, res) {
|
app.get("/api/loadwhiteboard", function (req, res) {
|
||||||
var wid = req["query"]["wid"];
|
var wid = req["query"]["wid"];
|
||||||
@ -91,7 +92,7 @@ function startBackendServer(port) {
|
|||||||
|
|
||||||
var name = fields["name"] || "";
|
var name = fields["name"] || "";
|
||||||
var date = fields["date"] || +new Date();
|
var date = fields["date"] || +new Date();
|
||||||
var filename = whiteboardId + "_" + date + ".png";
|
var filename = whiteboardId + "_" + date + "." + imageDownloadFormat;
|
||||||
var webdavaccess = fields["webdavaccess"] || false;
|
var webdavaccess = fields["webdavaccess"] || false;
|
||||||
try {
|
try {
|
||||||
webdavaccess = JSON.parse(webdavaccess);
|
webdavaccess = JSON.parse(webdavaccess);
|
||||||
|
@ -283,15 +283,16 @@ function initWhiteboard() {
|
|||||||
showBasicAlert("Please drag the image into the browser.");
|
showBasicAlert("Please drag the image into the browser.");
|
||||||
});
|
});
|
||||||
|
|
||||||
// save image as png
|
console.log(ConfigService.imageDownloadFormat, ConfigService.showSmallestScreenIndicator);
|
||||||
|
// save image as imgae
|
||||||
$("#saveAsImageBtn").click(function () {
|
$("#saveAsImageBtn").click(function () {
|
||||||
whiteboard.getImageDataBase64(function (imgData) {
|
whiteboard.getImageDataBase64(ConfigService.imageDownloadFormat, function (imgData) {
|
||||||
var w = window.open("about:blank"); //Firefox will not allow downloads without extra window
|
var w = window.open("about:blank"); //Firefox will not allow downloads without extra window
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
//FireFox seems to require a setTimeout for this to work.
|
//FireFox seems to require a setTimeout for this to work.
|
||||||
var a = document.createElement("a");
|
var a = document.createElement("a");
|
||||||
a.href = imgData;
|
a.href = imgData;
|
||||||
a.download = "whiteboard.png";
|
a.download = "whiteboard." + ConfigService.imageDownloadFormat;
|
||||||
w.document.body.appendChild(a);
|
w.document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
w.document.body.removeChild(a);
|
w.document.body.removeChild(a);
|
||||||
@ -380,7 +381,9 @@ function initWhiteboard() {
|
|||||||
localStorage.setItem("webdavusername", webdavusername);
|
localStorage.setItem("webdavusername", webdavusername);
|
||||||
var webdavpassword = webDavHtml.find(".webdavpassword").val();
|
var webdavpassword = webDavHtml.find(".webdavpassword").val();
|
||||||
localStorage.setItem("webdavpassword", webdavpassword);
|
localStorage.setItem("webdavpassword", webdavpassword);
|
||||||
whiteboard.getImageDataBase64(function (base64data) {
|
whiteboard.getImageDataBase64(ConfigService.imageDownloadFormat, function (
|
||||||
|
base64data
|
||||||
|
) {
|
||||||
var webdavaccess = {
|
var webdavaccess = {
|
||||||
webdavserver: webdavserver,
|
webdavserver: webdavserver,
|
||||||
webdavpath: webdavpath,
|
webdavpath: webdavpath,
|
||||||
|
@ -32,6 +32,14 @@ class ConfigService {
|
|||||||
return this.#showSmallestScreenIndicator;
|
return this.#showSmallestScreenIndicator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
#imageDownloadFormat = "png";
|
||||||
|
get imageDownloadFormat() {
|
||||||
|
return this.#imageDownloadFormat;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {{minDistDelta: number, minTimeDelta: number}}
|
* @type {{minDistDelta: number, minTimeDelta: number}}
|
||||||
*/
|
*/
|
||||||
@ -57,10 +65,16 @@ class ConfigService {
|
|||||||
this.#configFromServer = configFromServer;
|
this.#configFromServer = configFromServer;
|
||||||
|
|
||||||
const { common } = configFromServer;
|
const { common } = configFromServer;
|
||||||
const { onWhiteboardLoad, showSmallestScreenIndicator, performance } = common;
|
const {
|
||||||
|
onWhiteboardLoad,
|
||||||
|
showSmallestScreenIndicator,
|
||||||
|
imageDownloadFormat,
|
||||||
|
performance,
|
||||||
|
} = common;
|
||||||
|
|
||||||
this.#onWhiteboardLoad = onWhiteboardLoad;
|
this.#onWhiteboardLoad = onWhiteboardLoad;
|
||||||
this.#showSmallestScreenIndicator = showSmallestScreenIndicator;
|
this.#showSmallestScreenIndicator = showSmallestScreenIndicator;
|
||||||
|
this.#imageDownloadFormat = imageDownloadFormat;
|
||||||
this.#refreshInfoInterval = 1000 / performance.refreshInfoFreq;
|
this.#refreshInfoInterval = 1000 / performance.refreshInfoFreq;
|
||||||
|
|
||||||
console.log("Whiteboard config from server:", configFromServer, "parsed:", this);
|
console.log("Whiteboard config from server:", configFromServer, "parsed:", this);
|
||||||
|
@ -1173,7 +1173,7 @@ const whiteboard = {
|
|||||||
refreshUserBadges() {
|
refreshUserBadges() {
|
||||||
this.cursorContainer.find(".userbadge").remove();
|
this.cursorContainer.find(".userbadge").remove();
|
||||||
},
|
},
|
||||||
getImageDataBase64(callback) {
|
getImageDataBase64(format, callback) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
var width = this.mouseOverlay.width();
|
var width = this.mouseOverlay.width();
|
||||||
var height = this.mouseOverlay.height();
|
var height = this.mouseOverlay.height();
|
||||||
@ -1193,6 +1193,11 @@ const whiteboard = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var destCtx = copyCanvas.getContext("2d"); //Draw the maincanvas to the exportcanvas
|
var destCtx = copyCanvas.getContext("2d"); //Draw the maincanvas to the exportcanvas
|
||||||
|
if (format === "jpeg") {
|
||||||
|
//Set white background for jpeg images
|
||||||
|
destCtx.fillStyle = "#FFFFFF";
|
||||||
|
destCtx.fillRect(0, 0, width, height);
|
||||||
|
}
|
||||||
destCtx.drawImage(this.canvas, 0, 0);
|
destCtx.drawImage(this.canvas, 0, 0);
|
||||||
|
|
||||||
var textBoxCnt = 0;
|
var textBoxCnt = 0;
|
||||||
@ -1219,7 +1224,7 @@ const whiteboard = {
|
|||||||
|
|
||||||
function checkForReturn() {
|
function checkForReturn() {
|
||||||
if (textBoxCnt == 0) {
|
if (textBoxCnt == 0) {
|
||||||
var url = copyCanvas.toDataURL();
|
var url = copyCanvas.toDataURL("image/" + format);
|
||||||
callback(url);
|
callback(url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user