move examples
This commit is contained in:
parent
45ff502b55
commit
c3047a1586
47 changed files with 52 additions and 39 deletions
8
examples/images/image_manipulation/css/example.css
Normal file
8
examples/images/image_manipulation/css/example.css
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
body {
|
||||
margin: 16px;
|
||||
background-color: rgb(240, 240, 240);
|
||||
}
|
||||
img {
|
||||
display: block;
|
||||
margin: 8px 0 0 2px;
|
||||
}
|
||||
13
examples/images/image_manipulation/index.html
Normal file
13
examples/images/image_manipulation/index.html
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Image Manipulation</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<link rel="shortcut icon" type="image/png" href="../../../source/Ox.UI/themes/classic/png/icon16.png"/>
|
||||
<link rel="stylesheet" type="text/css" href="css/example.css"/>
|
||||
<script type="text/javascript" src="../../../dev/Ox.js"></script>
|
||||
<script type="text/javascript" src="js/example.js"></script>
|
||||
<script>window.addEventListener('message', function(e) { e.origin == window.location.origin && eval(e.data); });</script>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
90
examples/images/image_manipulation/js/example.js
Normal file
90
examples/images/image_manipulation/js/example.js
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
Load the image module.
|
||||
*/
|
||||
Ox.load('Image', function() {
|
||||
|
||||
/*
|
||||
Load a sample image (about which you can read more on
|
||||
<a href="see http://en.wikipedia.org/wiki/Lenna">Wikipedia</a>).
|
||||
*/
|
||||
Ox.Image('png/lenna256.png', function(image) {
|
||||
|
||||
/*
|
||||
Create some DOM elements.
|
||||
*/
|
||||
var $body = Ox.$('body'),
|
||||
$select = Ox.$('<select>').on({change: change}).appendTo($body),
|
||||
$image = Ox.$('<img>').attr({src: image.src()}).appendTo($body);
|
||||
|
||||
[
|
||||
'Method...', 'src("png/lenna256.png")',
|
||||
'blur(2)', 'blur(4)',
|
||||
'channel("r")', 'channel("g")', 'channel("b")',
|
||||
'channel("h")', 'channel("s")', 'channel("l")',
|
||||
'contour()',
|
||||
'depth(1)', 'depth(2)', 'depth(4)',
|
||||
'drawCircle([128, 128], 64, {"fill": "rgba(0, 0, 0, 0.5)"})',
|
||||
'drawLine([[64, 64], [192, 192]], {"color": "green", "width": 2})',
|
||||
'drawPath([[64, 64], [192, 64], [64, 192]], {"close": true})',
|
||||
'drawRectangle([64, 64], [128, 128], {"fill": "red", "width": 0})',
|
||||
'drawText("?", [16, 240], {"color": "blue", "font": "64px Arial"})',
|
||||
'edges()', 'emboss()',
|
||||
'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)',
|
||||
'filter([0, 1, 0, 1, -2, 1, 0, 1, 0])',
|
||||
'hue(-60)', 'hue(60)',
|
||||
'invert()',
|
||||
'lightness(-0.5)', 'lightness(0.5)',
|
||||
'map(function(v, xy) { return Ox.sum(xy) % 2 ? [0, 0, 0] : v; })',
|
||||
'mosaic(4)', 'motionBlur()',
|
||||
'photocopy()', 'pixel([16, 16], [255, 255, 255])', 'posterize()',
|
||||
'saturation(-0.5)', 'saturation(0.5)',
|
||||
'sharpen()', 'solarize()'
|
||||
].forEach(function(method) {
|
||||
Ox.$('<option>').html(method).appendTo($select);
|
||||
});
|
||||
|
||||
function change() {
|
||||
var value = $select.val(),
|
||||
match = value.match(/^(\w+)\((.*?)\)$/),
|
||||
fn = match[1], args;
|
||||
/*
|
||||
The <code>map</code> method takes a function as its argument, which
|
||||
we can't <code>JSON.parse</code>, but have to <code>eval</code>.
|
||||
*/
|
||||
try {
|
||||
args = JSON.parse('[' + match[2] + ']');
|
||||
} catch(e) {
|
||||
args = [eval('f = ' + match[2])];
|
||||
}
|
||||
/*
|
||||
The <code>src</code> and <code>encode</code> methods are
|
||||
asynchronous and take a callback function.
|
||||
*/
|
||||
if (fn == 'src' || fn == 'encode') {
|
||||
image[fn].apply(null, args.concat(function(image) {
|
||||
$image.attr({src: image.src()});
|
||||
}));
|
||||
/*
|
||||
The <code>decode</code> method is asynchronous too, and its callback
|
||||
function gets passed a string.
|
||||
*/
|
||||
} else if (fn == 'decode') {
|
||||
image[fn].apply(null, args.concat(function(str) {
|
||||
alert(str);
|
||||
}));
|
||||
/*
|
||||
All other methods simply return the image.
|
||||
*/
|
||||
} else {
|
||||
$image.attr({src: image[fn].apply(null, args).src()});
|
||||
}
|
||||
$select.val('Method...');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
BIN
examples/images/image_manipulation/png/lenna256.png
Normal file
BIN
examples/images/image_manipulation/png/lenna256.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 116 KiB |
16
examples/images/steganography/css/example.css
Normal file
16
examples/images/steganography/css/example.css
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
body {
|
||||
margin: 0;
|
||||
}
|
||||
table {
|
||||
border-spacing: 8px;
|
||||
}
|
||||
td {
|
||||
padding: 0;
|
||||
border-collapse: collapse;
|
||||
font-family: Lucida Grande, Segoe UI, DejaVu Sans, Lucida Sans Unicode, Helvetica, Arial, sans-serif;
|
||||
font-size: 12px;
|
||||
vertical-align: top;
|
||||
}
|
||||
td:first-child {
|
||||
width: 320px;
|
||||
}
|
||||
13
examples/images/steganography/index.html
Normal file
13
examples/images/steganography/index.html
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Steganograpy</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<link rel="shortcut icon" type="image/png" href="../../../source/Ox.UI/themes/classic/png/icon16.png"/>
|
||||
<link rel="stylesheet" type="text/css" href="css/example.css"/>
|
||||
<script type="text/javascript" src="../../../dev/Ox.js"></script>
|
||||
<script type="text/javascript" src="js/example.js"></script>
|
||||
<script>window.addEventListener('message', function(e) { e.origin == window.location.origin && eval(e.data); });</script>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
126
examples/images/steganography/js/example.js
Normal file
126
examples/images/steganography/js/example.js
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
Ox.Image provides a pair of methods, <code>encode</code> and
|
||||
<code>decode</code>, which can be used for
|
||||
<a href="http://en.wikipedia.org/wiki/Steganography">steganography</a>, i.e. to
|
||||
add a hidden message to an image.<br><br>
|
||||
The signature of the <code>encode</code> function is
|
||||
<code>image.encode(message, deflate, mode, callback)</code>.
|
||||
<code>deflate</code> turns deflate-compression on or off, and <code>mode</code>
|
||||
determines which bits of the image the message will be written to — but
|
||||
for most purposes, the default values (<code>true</code> and <code>0</code>)
|
||||
are fine, so <code>deflate</code> and <code>mode</code> can be omitted.<br>
|
||||
<br>
|
||||
In this example, we demonstrate a valid use case for <code>deflate</code> and
|
||||
<code>mode</code>: To encode an decoy message (a line of text), which will be
|
||||
relatively easy to detect, and then the the actual message, (another image,
|
||||
itself containing another line of text), which will be harder to detect.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Ox.load('Image', function() {
|
||||
|
||||
var $table = Ox.$('<table>').appendTo(Ox.$('body')),
|
||||
$tr,
|
||||
text = {
|
||||
iceland: 'The first image he told me about '
|
||||
+ 'was of three children on a road in Iceland in 1965.',
|
||||
vietnam: 'He said for him it was the image of happiness, '
|
||||
+ 'and that he had often tried to link it to other images, '
|
||||
+ 'but it had never worked.'
|
||||
};
|
||||
|
||||
encode(decode);
|
||||
|
||||
/*
|
||||
So we first encode two lines text into two images, by writing them bit by
|
||||
bit (without compression, <code>deflate = false</code>), into the least
|
||||
significant bit of each 8-bit RGB value (<code>mode = 1</code>). Then we
|
||||
encode one image into the other: We take the (deflate-compressed,
|
||||
<code>deflate = true</code>) data URL of the source image and flip, if
|
||||
needed, the second least significant bit of each RGB value of the target
|
||||
image, so that the number of bits set to 1, modulo 2 (for example: 10101010
|
||||
-> 0), is the bit we're encoding (<code>mode = -1</code>). As the least
|
||||
significant bit remains untouched, this will preserve the encoded text.
|
||||
*/
|
||||
function encode(callback) {
|
||||
status('Load iceland.png');
|
||||
Ox.Image('png/iceland.png', function(iceland) {
|
||||
result(Ox.$('<img>').attr({src: iceland.src()}));
|
||||
status(
|
||||
'Encode the text <i>"' + text.iceland + '"</i> into '
|
||||
+ 'the least significant bits of iceland.png'
|
||||
);
|
||||
iceland.encode(text.iceland, false, 1, function(iceland) {
|
||||
result(Ox.$('<img>').attr({src: iceland.src()}));
|
||||
status('Load vietnam.png');
|
||||
Ox.Image('png/vietnam.png', function(vietnam) {
|
||||
result(Ox.$('<img>').attr({src: vietnam.src()}));
|
||||
status(
|
||||
'Encode the text <i>"' + text.vietnam + '"</i> into'
|
||||
+ ' the least significant bits of vietnam.png'
|
||||
);
|
||||
vietnam.encode(text.vietnam, false, 1, function(vietnam) {
|
||||
result(Ox.$('<img>').attr({src: vietnam.src()}));
|
||||
status(
|
||||
'Encode vietnam.png into iceland.png '
|
||||
+ 'by flipping the second least significant bits'
|
||||
);
|
||||
iceland.encode(vietnam.src(), -1, function(iceland) {
|
||||
result(Ox.$('<img>').attr({src: iceland.src()}));
|
||||
callback(iceland);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
Finally, we decode all the data again.
|
||||
*/
|
||||
function decode(iceland) {
|
||||
status('Decode the least signigicant bits of iceland.png');
|
||||
iceland.decode(false, 1, function(str) {
|
||||
result(str);
|
||||
status('Decode all bits of iceland.png');
|
||||
iceland.decode(-1, function(src) {
|
||||
result(
|
||||
src.slice(0, 32) + '<i> ... ['
|
||||
+ Ox.formatNumber(src.length - 64)
|
||||
+ ' more bytes] ... </i>' + src.slice(-32)
|
||||
);
|
||||
status('Load as vietnam.png');
|
||||
Ox.Image(src, function(image) {
|
||||
result(Ox.$('<img>').attr({src: src}));
|
||||
status('Decode the least significant bits of vietnam.png');
|
||||
image.decode(false, 1, function(str) {
|
||||
result(str);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function status(value) {
|
||||
var $td = Ox.$('<td>');
|
||||
if (Ox.isString(value)) {
|
||||
$td.html(
|
||||
value.replace(/(\w+\.png)/g, '<b>$1</b>')
|
||||
);
|
||||
} else {
|
||||
$td.append(value);
|
||||
}
|
||||
$tr = Ox.$('<tr>').append($td).appendTo($table);
|
||||
}
|
||||
|
||||
function result(value) {
|
||||
var $td = Ox.$('<td>');
|
||||
if (Ox.isString(value)) {
|
||||
$td.html(value);
|
||||
} else {
|
||||
$td.append(value);
|
||||
}
|
||||
$tr.append($td);
|
||||
}
|
||||
|
||||
});
|
||||
BIN
examples/images/steganography/png/iceland.png
Normal file
BIN
examples/images/steganography/png/iceland.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 250 KiB |
BIN
examples/images/steganography/png/vietnam.png
Normal file
BIN
examples/images/steganography/png/vietnam.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
Loading…
Add table
Add a link
Reference in a new issue