Since the plugin processes images in the browser, it returns the watermarked image as a base64 URL via the done callback. This is useful for exporting images without a server.
Single Image
$(function() {
$('<img>', {
src: 'http://i.imgur.com/AAPx3rB.jpg'
}).watermark({
done: function (imgURL) {
console.log(imgURL);
}
});
});
Multiple Images (Batch)
To process multiple images, you can use a $.Deferred object to track when all images have finished processing.
$(function() {
var inputImages = ['http://i.imgur.com/AAPx3rB.jpg', 'http://i.imgur.com/39dfdPw.jpg', 'http://i.imgur.com/3OfclQY.jpg'];
var outputImages = [];
var defer = $.Deferred();
$.when(defer).done(function () {
console.log(outputImages);
});
$.each(inputImages, function (i, v) {
$('<img>', {
src: v
}).watermark({
done: function (imgURL) {
outputImages[i] = imgURL;
if (i + 1 === inputImages.length) {
defer.resolve();
}
}
});
});
});
$(function() {
var inputImages = ['http://i.imgur.com/AAPx3rB.jpg', 'http://i.imgur.com/39dfdPw.jpg', 'http://i.imgur.com/3OfclQY.jpg'];
var outputImages = [];
var defer = $.Deferred();
$.when(defer).done(function () {
console.log(outputImages);
});
$.each(inputImages, function (i, v) {
$('<img>', {
src: v
}).watermark({
done: function (imgURL) {
outputImages[i] = imgURL;
if (i + 1 === inputImages.length) {
defer.resolve();
}
}
});
});
});