mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-14 04:10:04 +01:00
fixed replaceImage (#151)
* 1.0.0 * Fixed Replace Image * Added test to check if replaceImage works
This commit is contained in:
committed by
Jeffrey Warren
parent
73e5d14569
commit
3f99e2b44c
2571
dist/image-sequencer.js
vendored
2571
dist/image-sequencer.js
vendored
File diff suppressed because one or more lines are too long
@@ -4,7 +4,7 @@
|
|||||||
"description": "A modular JavaScript image manipulation library modeled on a storyboard.",
|
"description": "A modular JavaScript image manipulation library modeled on a storyboard.",
|
||||||
"main": "src/ImageSequencer.js",
|
"main": "src/ImageSequencer.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "tape test/*.js | tap-spec; browserify test/image-sequencer.js test/chain.js | tape-run --render=\"tap-spec\""
|
"test": "tape test/*.js | tap-spec; browserify test/image-sequencer.js test/chain.js test/replace.js | tape-run --render=\"tap-spec\""
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -169,7 +169,8 @@ ImageSequencer = function ImageSequencer(options) {
|
|||||||
|
|
||||||
function replaceImage(selector,steps,options) {
|
function replaceImage(selector,steps,options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
return require('./ReplaceImage')(this,selector,steps);
|
options.callback = options.callback || function() {};
|
||||||
|
return require('./ReplaceImage')(this,selector,steps,options);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setUI(UI) {
|
function setUI(UI) {
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
function ReplaceImage(ref,selector,steps,options) {
|
function ReplaceImage(ref,selector,steps,options) {
|
||||||
if(!ref.options.inBrowser) return false; // This isn't for Node.js
|
if(!ref.options.inBrowser) return false; // This isn't for Node.js
|
||||||
|
var tempSequencer = ImageSequencer({ui: false});
|
||||||
var this_ = ref;
|
var this_ = ref;
|
||||||
var input = document.querySelectorAll(selector);
|
var input = document.querySelectorAll(selector);
|
||||||
var images = [];
|
var images = [];
|
||||||
for (var i = 0; i < input.length; i++)
|
for (var i = 0; i < input.length; i++) {
|
||||||
if (input[i] instanceof HTMLImageElement) images.push(input[i]);
|
if (input[i] instanceof HTMLImageElement) images.push(input[i]);
|
||||||
for (var i in images) {
|
}
|
||||||
var the_image = images[i];
|
|
||||||
var url = images[i].src;
|
function replaceImage (img, steps) {
|
||||||
|
var url = img.src;
|
||||||
var ext = url.split('.').pop();
|
var ext = url.split('.').pop();
|
||||||
|
|
||||||
var xmlHTTP = new XMLHttpRequest();
|
var xmlHTTP = new XMLHttpRequest();
|
||||||
@@ -25,11 +27,19 @@ function ReplaceImage(ref,selector,steps,options) {
|
|||||||
else make(url);
|
else make(url);
|
||||||
|
|
||||||
function make(url) {
|
function make(url) {
|
||||||
this_.loadImage('default',url).addSteps('default',steps).run(function(out){
|
tempSequencer.loadImage(url, function(){
|
||||||
the_image.src = out;
|
this.addSteps(steps).run(function(out){
|
||||||
|
img.src = out;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < images.length; i++) {
|
||||||
|
replaceImage(images[i],steps);
|
||||||
|
if (i == images.length-1)
|
||||||
|
options.callback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ReplaceImage;
|
module.exports = ReplaceImage;
|
||||||
|
|||||||
25
test/replace.js
Normal file
25
test/replace.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var fs = require('fs');
|
||||||
|
var test = require('tape');
|
||||||
|
|
||||||
|
require('../src/ImageSequencer.js');
|
||||||
|
|
||||||
|
var sequencer = ImageSequencer({ ui: false });
|
||||||
|
var red = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAQABADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFQEBAQAAAAAAAAAAAAAAAAAABgj/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwCdABykX//Z";
|
||||||
|
|
||||||
|
if(typeof(document) !== "undefined") {
|
||||||
|
var image = document.createElement("img");
|
||||||
|
image.src = red;
|
||||||
|
document.body.appendChild(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('replaceImage works.', function (t){
|
||||||
|
if (typeof(document) === "undefined")
|
||||||
|
t.end();
|
||||||
|
|
||||||
|
sequencer.replaceImage("img","invert",{ callback: function(){
|
||||||
|
t.equal(0,0, "replaceImage works");
|
||||||
|
t.end();
|
||||||
|
} });
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user