2011-06-19 17:40:53 +02:00
|
|
|
Ox.load('Image', function() {
|
|
|
|
|
|
2011-06-21 11:16:23 +02:00
|
|
|
// see http://en.wikipedia.org/wiki/Lenna
|
|
|
|
|
|
2012-04-14 11:46:46 +02:00
|
|
|
Ox.Image('png/lenna256.png', function(image) {
|
2011-06-21 11:16:23 +02:00
|
|
|
var body = Ox.element('body'),
|
|
|
|
|
select = Ox.element('<select>').appendTo(body);
|
2011-09-08 01:53:19 +00:00
|
|
|
[
|
2012-04-14 11:46:46 +02:00
|
|
|
'Method...', 'src("png/lenna256.png")',
|
|
|
|
|
'blur(1)', 'blur(5)',
|
2011-09-08 08:16:31 +00:00
|
|
|
'channel("r")', 'channel("g")', 'channel("b")', 'channel("a")',
|
2011-09-08 01:53:19 +00:00
|
|
|
'channel("h")', 'channel("s")', 'channel("l")',
|
2011-09-09 10:41:13 +00:00
|
|
|
'contour()',
|
|
|
|
|
'depth(1)', 'depth(2)', 'depth(4)',
|
2012-04-14 11:46:46 +02:00
|
|
|
'drawCircle([128, 128], 64, {"fill": "rgba(0, 0, 0, 0.5)"})',
|
|
|
|
|
'drawLine([[64, 64], [192, 192]], {"color": "red", "width": 2})',
|
|
|
|
|
'drawPath([[64, 64], [192, 64], [64, 192]], {"close": true, "fill": "rgba(0, 0, 0, 0.5)", "width": 2})',
|
|
|
|
|
'drawRectangle([64, 64], [128, 128], {"fill": "rgba(0, 0, 0, 0.5)"})',
|
|
|
|
|
'drawText("?", [128, 160], {"font": "64px Arial", "outline": "2px white"})',
|
2011-09-09 10:41:13 +00:00
|
|
|
'edges()', 'emboss()',
|
2011-09-08 21:39:07 +00:00
|
|
|
'encode("secret")', 'decode()',
|
|
|
|
|
'encode("secret", false)', 'decode(false)',
|
|
|
|
|
'encode("secret", 1)', 'decode(1)',
|
|
|
|
|
'encode("secret", false, 15)', 'decode(false, 15)',
|
|
|
|
|
'encode("secret", 127)', 'decode(127)',
|
2011-09-08 08:16:31 +00:00
|
|
|
'hue(-60)', 'hue(60)',
|
2011-09-08 01:53:19 +00:00
|
|
|
'invert()',
|
|
|
|
|
'lightness(-0.5)', 'lightness(0.5)',
|
2011-09-09 10:41:13 +00:00
|
|
|
'mosaic(4)', 'motionBlur()', 'photocopy()', 'posterize()',
|
2011-09-08 08:16:31 +00:00
|
|
|
'resize(256, 256)', 'resize(512, 512)',
|
2011-09-08 01:53:19 +00:00
|
|
|
'saturation(-0.5)', 'saturation(0.5)',
|
2011-09-09 10:41:13 +00:00
|
|
|
'scale(0.5, -1)',
|
2012-04-14 11:46:46 +02:00
|
|
|
'sharpen()', 'solarize()'
|
2011-09-08 01:53:19 +00:00
|
|
|
].forEach(function(filter) {
|
2011-06-21 11:16:23 +02:00
|
|
|
Ox.element('<option>').html(filter).appendTo(select);
|
|
|
|
|
});
|
|
|
|
|
select[0].onchange = function() {
|
|
|
|
|
if (select[0].value[0] == select[0].value[0].toLowerCase()) {
|
2012-04-14 11:46:46 +02:00
|
|
|
//Ox.print(select[0].value.match(/^(\w+)\((.+)\)$/))
|
|
|
|
|
var match = select[0].value.match(/^(\w+)\((.*?)\)$/),
|
|
|
|
|
fn = match[1],
|
|
|
|
|
args = JSON.parse('[' + match[2] + ']');
|
|
|
|
|
//Ox.print('??', fn, args, image.drawLine)
|
2011-09-08 01:53:19 +00:00
|
|
|
if (fn == 'encode' || fn == 'src') {
|
|
|
|
|
image[fn].apply(null, Ox.merge(args, function(image) {
|
2012-04-14 11:46:46 +02:00
|
|
|
Ox.element('#image').attr({
|
2011-09-08 01:53:19 +00:00
|
|
|
src: image.src()
|
2012-04-14 11:46:46 +02:00
|
|
|
});
|
2011-09-08 01:53:19 +00:00
|
|
|
}));
|
|
|
|
|
} else if (fn == 'decode') {
|
|
|
|
|
image[fn].apply(null, Ox.merge(args, function(str) {
|
|
|
|
|
alert(str);
|
|
|
|
|
}));
|
|
|
|
|
} else {
|
2012-04-14 11:46:46 +02:00
|
|
|
Ox.element('#image').attr({
|
2011-09-08 01:53:19 +00:00
|
|
|
src: image[fn].apply(null, args).src()
|
|
|
|
|
});
|
2012-04-14 11:46:46 +02:00
|
|
|
Ox.print('DONE')
|
2011-09-08 01:53:19 +00:00
|
|
|
}
|
|
|
|
|
select[0].selectedIndex = 0;
|
2011-06-21 11:16:23 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ox.element('<br>').appendTo(body);
|
|
|
|
|
Ox.element('<img>').attr({
|
2012-04-14 11:46:46 +02:00
|
|
|
id: 'image',
|
2011-09-08 01:53:19 +00:00
|
|
|
src: image.src()
|
2011-06-21 11:16:23 +02:00
|
|
|
}).appendTo(body);
|
|
|
|
|
//Ox.element('<img>').attr({src: image.saturation(0.5).blur().url()}).appendTo(Ox.element('body'));
|
2011-06-19 17:40:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|