Skip to content

Commit 4fedbce

Browse files
committed
Added function for downloading spectrum img
1 parent 1d34e11 commit 4fedbce

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

examples/capture/capture.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,27 @@ $W = {
161161
this_.getRecentCalibrations("#calibration_id");
162162
},
163163

164+
downloadSpectrum: function() {
165+
function getFormattedTime() {
166+
let current_date = new Date();
167+
let year = current_date.getFullYear();
168+
let month = current_date.getMonth() + 1;
169+
let day = current_date.getDate();
170+
let hours = current_date.getHours();
171+
let minutes = current_date.getMinutes();
172+
let seconds = current_date.getSeconds();
173+
return (year + '-' + month + '-' + day + '-' + hours + '-' + minutes + '-' + seconds);
174+
}
175+
176+
let base64_imgdata = $('#dataurl').val($W.canvas.toDataURL())[0].defaultValue;
177+
console.log(base64_imgdata);
178+
179+
let a = document.createElement('a');
180+
a.href = base64_imgdata;
181+
a.download = ('spectrum_img-' + getFormattedTime() + '.png');
182+
a.click();
183+
},
184+
164185
getRecentCalibrations: function(selector) {
165186
$.ajax({
166187
url: "/capture/recent_calibrations.json?calibration_id=" + $W.calibration_id,

0 commit comments

Comments
 (0)