Synchronize resize fields, resize image when importing

This commit is contained in:
jdescottes
2013-10-23 01:01:35 +02:00
parent 6c0f54032d
commit 3dde3504d1
8 changed files with 119 additions and 15 deletions

22
js/utils/ImageResizer.js Normal file
View File

@@ -0,0 +1,22 @@
(function () {
var ns = $.namespace('pskl.utils');
ns.ImageResizer = {
resizeNearestNeighbour : function (image, targetWidth, targetHeight) {
},
resize : function (image, targetWidth, targetHeight) {
var canvas = pskl.CanvasUtils.createCanvas(targetWidth, targetHeight);
var context = canvas.getContext('2d');
context.save();
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;
}
};
})();