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/
This commit is contained in:
parent
79d6c265e2
commit
2eeb4549ce
1 changed files with 16 additions and 6 deletions
|
@ -305,6 +305,7 @@ Image.prototype.update = function(data) {
|
||||||
var thumbnail;
|
var thumbnail;
|
||||||
var image = this.getHelmaImage(mime, isLayout ? null :
|
var image = this.getHelmaImage(mime, isLayout ? null :
|
||||||
res.handlers.site.imageDimensionLimits);
|
res.handlers.site.imageDimensionLimits);
|
||||||
|
|
||||||
this.width = image.width;
|
this.width = image.width;
|
||||||
this.height = image.height;
|
this.height = image.height;
|
||||||
|
|
||||||
|
@ -332,7 +333,7 @@ Image.prototype.update = function(data) {
|
||||||
this.fileName = fileName;
|
this.fileName = fileName;
|
||||||
if (thumbnail) this.thumbnailName = this.name + '_small' + extension;
|
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();
|
this.contentLength = this.getFile().getLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,14 +505,19 @@ Image.prototype.getJSON = function() {
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
Image.prototype.getHelmaImage = function(mime, dimensionLimits) {
|
Image.prototype.getHelmaImage = function(mime, dimensionLimits) {
|
||||||
if (!dimensionLimits) dimensionLimits = [Infinity, Infinity];
|
if (!dimensionLimits) dimensionLimits = [];
|
||||||
|
|
||||||
var maxWidth = dimensionLimits[0];
|
var maxWidth = dimensionLimits[0] || Infinity;
|
||||||
var maxHeight = dimensionLimits[1];
|
var maxHeight = dimensionLimits[1] || Infinity;
|
||||||
|
|
||||||
|
var result = {
|
||||||
|
data: null,
|
||||||
|
width: 0,
|
||||||
|
height: 0
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var image = new helma.Image(mime.inputStream);
|
var image = new helma.Image(mime.inputStream);
|
||||||
|
|
||||||
var factorH = 1, factorV = 1;
|
var factorH = 1, factorV = 1;
|
||||||
|
|
||||||
if (maxWidth && image.width > maxWidth) {
|
if (maxWidth && image.width > maxWidth) {
|
||||||
|
@ -533,9 +539,13 @@ Image.prototype.getHelmaImage = function(mime, dimensionLimits) {
|
||||||
if (mime.contentType.endsWith('gif')) {
|
if (mime.contentType.endsWith('gif')) {
|
||||||
image.reduceColors(256);
|
image.reduceColors(256);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.data = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
return image;
|
result.width = image.width;
|
||||||
|
result.height = image.height;
|
||||||
|
return result;
|
||||||
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
app.log(ex);
|
app.log(ex);
|
||||||
|
|
Loading…
Add table
Reference in a new issue