-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmirror.js
47 lines (41 loc) · 1.41 KB
/
mirror.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Caman.Plugin.register("mirror",function(vertical){
var canvas, ctx, id;
copyAttributes = function(from, to, opts) {
var attr, _i, _len, _ref, _ref1, _results;
if (opts == null) {
opts = {};
}
_ref = from.attributes;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
attr = _ref[_i];
if ((opts.except != null) && (_ref1 = attr.nodeName, __indexOf.call(opts.except, _ref1) >= 0)) {
continue;
}
_results.push(to.setAttribute(attr.nodeName, attr.nodeValue));
}
return _results;
};
// Support NodeJS by checking for exports object
if (typeof exports !== "undefined" && exports !== null) {
canvas = new Canvas(this.dimensions.width, this.dimensions.height);
} else {
canvas = document.createElement('canvas');
copyAttributes(this.canvas, canvas);
canvas.width = this.dimensions.width;
canvas.height = this.dimensions.height;
}
ctx = canvas.getContext('2d');
if(vertical==true){
ctx.translate(0, canvas.height);
ctx.scale(1, -1)
}else{
ctx.translate(canvas.width,0);
ctx.scale(-1, 1)
}
ctx.drawImage(this.canvas, 0, 0);
return this.replaceCanvas(canvas);
});
Caman.Filter.register("mirror", function() {
this.processPlugin("mirror", arguments);
});