mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-13 11:50:02 +01:00
replaceImage
This commit is contained in:
35
src/ReplaceImage.js
Normal file
35
src/ReplaceImage.js
Normal file
@@ -0,0 +1,35 @@
|
||||
function ReplaceImage(ref,selector,steps) {
|
||||
if(!ref.options.inBrowser) return; // This isn't for Node.js
|
||||
this_ = ref;
|
||||
var input = document.querySelectorAll(selector);
|
||||
var images = [];
|
||||
for (i = 0; i < input.length; i++)
|
||||
if (input[i] instanceof HTMLImageElement) images.push(input[i]);
|
||||
for (i in images) {
|
||||
the_image = images[i];
|
||||
var url = images[i].src;
|
||||
var ext = url.split('.').pop();
|
||||
|
||||
var xmlHTTP = new XMLHttpRequest();
|
||||
xmlHTTP.open('GET', url, true);
|
||||
xmlHTTP.responseType = 'arraybuffer';
|
||||
xmlHTTP.onload = function(e) {
|
||||
var arr = new Uint8Array(this.response);
|
||||
var raw = String.fromCharCode.apply(null,arr);
|
||||
var base64 = btoa(raw);
|
||||
var dataURL="data:image/"+ext+";base64," + base64;
|
||||
make(dataURL);
|
||||
};
|
||||
|
||||
if(url.substr(0,11).toLowerCase()!="data:image/") xmlHTTP.send();
|
||||
else make(url);
|
||||
|
||||
function make(url) {
|
||||
this_.loadImage(url).addSteps('default',steps).run(function(out){
|
||||
the_image.src = out;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ReplaceImage;
|
||||
Reference in New Issue
Block a user