Added preview picture. Added a flow : start with only file input enabled

This commit is contained in:
jdescottes
2013-10-23 23:34:09 +02:00
parent 3dde3504d1
commit a0a1fa7bdf
9 changed files with 188 additions and 98 deletions

View File

@@ -2,21 +2,29 @@
var ns = $.namespace('pskl.utils');
ns.ImageResizer = {
resizeNearestNeighbour : function (image, targetWidth, targetHeight) {
},
resize : function (image, targetWidth, targetHeight) {
resize : function (image, targetWidth, targetHeight, smoothingEnabled) {
var canvas = pskl.CanvasUtils.createCanvas(targetWidth, targetHeight);
var context = canvas.getContext('2d');
context.save();
if (!smoothingEnabled) {
this.disableSmoothingOnContext(context);
}
context.translate(canvas.width / 2, canvas.height / 2);
context.scale(targetWidth / image.width, targetHeight / image.height);
context.drawImage(image, -image.width / 2, -image.height / 2);
context.restore();
return canvas;
},
disableSmoothingOnContext : function (context) {
context.imageSmoothingEnabled = false;
context.mozImageSmoothingEnabled = false;
context.oImageSmoothingEnabled = false;
context.webkitImageSmoothingEnabled = false;
context.msImageSmoothingEnabled = false;
}
};
})();