From 2eeb4549ce1b6198e6a63ffad15c832b769586c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobi=20Sch=C3=A4fer?= Date: Thu, 26 May 2016 12:31:12 +0200 Subject: [PATCH] fix: do not create a helma.Image instance if constraints are fulfilled obviously, helma.Image already compresses image data and a recent change actually removed code preventing this for images fulfilling the max width and height constraints see http://help.antville.org/stories/2239244/ --- code/Image/Image.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/code/Image/Image.js b/code/Image/Image.js index cd1eb51b..8ffff64e 100644 --- a/code/Image/Image.js +++ b/code/Image/Image.js @@ -305,6 +305,7 @@ Image.prototype.update = function(data) { var thumbnail; var image = this.getHelmaImage(mime, isLayout ? null : res.handlers.site.imageDimensionLimits); + this.width = image.width; this.height = image.height; @@ -332,7 +333,7 @@ Image.prototype.update = function(data) { this.fileName = fileName; if (thumbnail) this.thumbnailName = this.name + '_small' + extension; - this.writeFiles(image, thumbnail); + this.writeFiles(image.data || mime, thumbnail && thumbnail.data); this.contentLength = this.getFile().getLength(); } @@ -504,14 +505,19 @@ Image.prototype.getJSON = function() { * @returns {Object} */ Image.prototype.getHelmaImage = function(mime, dimensionLimits) { - if (!dimensionLimits) dimensionLimits = [Infinity, Infinity]; + if (!dimensionLimits) dimensionLimits = []; - var maxWidth = dimensionLimits[0]; - var maxHeight = dimensionLimits[1]; + var maxWidth = dimensionLimits[0] || Infinity; + var maxHeight = dimensionLimits[1] || Infinity; + + var result = { + data: null, + width: 0, + height: 0 + }; try { var image = new helma.Image(mime.inputStream); - var factorH = 1, factorV = 1; if (maxWidth && image.width > maxWidth) { @@ -533,9 +539,13 @@ Image.prototype.getHelmaImage = function(mime, dimensionLimits) { if (mime.contentType.endsWith('gif')) { image.reduceColors(256); } + + result.data = image; } - return image; + result.width = image.width; + result.height = image.height; + return result; } catch (ex) { app.log(ex);