Commit 6dc5a981 authored by bbaer's avatar bbaer
Browse files

size calculation now works with variables and based on original image

parent db36a79d
......@@ -48,6 +48,9 @@ $(function (n) {
this.isDown = false;
this.origX = 0;
this.origY = 0;
this.imageHeight = 0;
this.imageWidth = 0;
this.resizeWidth = 0;
this.userChangePossible = false;
this.overObject = false;
this.selectionActive = false;
......@@ -247,9 +250,11 @@ $(function (n) {
var inputField = $fabricElement.data('control-name');
var viewOnly = $fabricElement.data('view-only') || false;
var editImage = $fabricElement.data('edit-image') || false;
var resizeWidth = $fabricElement.data('image-resize-width') || 0;
this.parentElement = $fabricElement;
this.backgroundImage = $fabricElement.data('background-image') || false;
this.fabricJSON = $fabricElement.data('fabric-json') || false;
this.resizeWidth = resizeWidth;
var that = this;
if (viewOnly) {
......@@ -276,6 +281,8 @@ $(function (n) {
};
n.Fabric.prototype.prepareImageEditor = function(width, height) {
this.imageHeight = height;
this.imageWidth = width;
var ratio = height / width;
var canvas = document.createElement('canvas');
var that = this;
......@@ -762,9 +769,10 @@ $(function (n) {
var img = this.canvas.item(0);
var oldHeight = img.height;
var oldWidth = img.width;
var newSize = this.calculateImageSize();
var rotated = false;
img.height = 1200 * img.height / img.width;
img.width = 1200;
img.height = newSize.height;
img.width = newSize.width;
if (this.rotation === 90 || this.rotation === 270) {
// width is now height and viceversa
rotated = true;
......@@ -781,6 +789,24 @@ $(function (n) {
this.exportToPNG(oldHeight, oldWidth, rotated);
};
n.Fabric.prototype.calculateImageSize = function() {
var img = { width: this.imageWidth, height: this.imageHeight };
if (this.resizeWidth !== 0) {
if (this.rotation === 90 || this.rotation === 270) {
if (this.resizeWidth < this.imageHeight) {
img.height = this.resizeWidth;
img.width = this.resizeWidth * this.imageWidth / this.imageHeight;
}
} else {
if (this.resizeWidth < this.imageWidth) {
img.width = this.resizeWidth;
img.height = this.resizeWidth * this.imageHeight / this.imageWidth;
}
}
}
return img;
};
n.Fabric.prototype.exportToPNG = function(height, width, rotated) {
var png = this.canvas.toDataURL('png');
$("#target-png").attr("src", png);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment