mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-13 20:00:05 +01:00
Added URL support for Node.js client
This commit is contained in:
@@ -8,10 +8,21 @@ function LoadImage(ref, name, src, main_callback) {
|
|||||||
}
|
}
|
||||||
function CImage(src, callback) {
|
function CImage(src, callback) {
|
||||||
var datauri;
|
var datauri;
|
||||||
if (src.substring(0,11) == "data:image/") {
|
if (!!src.match(/^data:/i)) {
|
||||||
datauri = src;
|
datauri = src;
|
||||||
callback(datauri);
|
callback(datauri);
|
||||||
}
|
}
|
||||||
|
else if (!ref.options.inBrowser && !!src.match(/^https?:\/\//i)) {
|
||||||
|
require( src.match(/^(https?):\/\//i)[1] ).get(src,function(res){
|
||||||
|
var data = '';
|
||||||
|
var contentType = res.headers['content-type'];
|
||||||
|
res.setEncoding('base64');
|
||||||
|
res.on('data',function(chunk) {data += chunk;});
|
||||||
|
res.on('end',function() {
|
||||||
|
callback("data:"+contentType+";base64,"+data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
else if (ref.options.inBrowser) {
|
else if (ref.options.inBrowser) {
|
||||||
var ext = src.split('.').pop();
|
var ext = src.split('.').pop();
|
||||||
var image = document.createElement('img');
|
var image = document.createElement('img');
|
||||||
|
|||||||
@@ -40,18 +40,13 @@ test('loadImages loads a DataURL image and creates a step.', function (t){
|
|||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('loadImages loads a PATH image and creates a step. (NodeJS)', function (t){
|
if(!sequencer.options.inBrowser)
|
||||||
if(sequencer.options.inBrowser){
|
test('loadImages loads an image from PATH and creates a step. (NodeJS)', function (t){
|
||||||
t.equal(1,1,"Not applicable for Browser");
|
sequencer.loadImages('examples/red.jpg');
|
||||||
t.end();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sequencer.loadImages(red);
|
|
||||||
t.equal(sequencer.images.image1.steps.length, 1, "Initial Step Created");
|
t.equal(sequencer.images.image1.steps.length, 1, "Initial Step Created");
|
||||||
t.equal(typeof(sequencer.images.image1.steps[0].output.src), "string", "Initial output exists");
|
t.equal(typeof(sequencer.images.image1.steps[0].output.src), "string", "Initial output exists");
|
||||||
t.end();
|
t.end();
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
test('loadImage works too.', function (t){
|
test('loadImage works too.', function (t){
|
||||||
sequencer.loadImage('test2',red);
|
sequencer.loadImage('test2',red);
|
||||||
|
|||||||
Reference in New Issue
Block a user