Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function Thumbor(securityKey, thumborServerUrl) {
this.valignValue = null;
this.cropValues = null;
this.meta = false;
this.trimValue = null;
this.filtersCalls = [];
}

Expand All @@ -34,6 +35,9 @@ Thumbor.prototype = {
CENTER: 'center',
LEFT: 'left',

TOP_LEFT: 'top-left',
BOTTOM_RIGHT: 'bottom-right',

/**
* Set path of image
* @param {String} imagePath [description]
Expand Down Expand Up @@ -75,6 +79,10 @@ Thumbor.prototype = {
parts.push('meta');
}

if (this.trimValue) {
parts.push(this.trimValue);
}

if (this.cropValues) {
parts.push(
this.cropValues.left +
Expand Down Expand Up @@ -130,6 +138,34 @@ Thumbor.prototype = {

return parts;
},
/**
* Removes surrounding space in images using top-left pixel color unless specified otherwise.
* Overrides any previous call to `trim`.
* @param {String} orientation 'top-left', 'bottom-right'
* @param {Integer} tolerance between 0 and 442
*/
trim: function(orientation, tolerance) {
var trimOpts = ['trim'];

if (orientation !== undefined) {
if (orientation === this.TOP_LEFT || orientation === this.BOTTOM_RIGHT) {
trimOpts.push(orientation);
} else {
throw new Error('Orientation must be top-left or bottom-right.');
}
}

if (tolerance !== undefined) {
if (tolerance > 0 && tolerance < 442) {
trimOpts.push(tolerance);
} else {
throw new Error('Tolerance must be between 0 and 442.');
}
}

this.trimValue = trimOpts.join(':');
return this;
},
/**
* Resize the image to the specified dimensions. Overrides any previous call
* to `fitIn` or `resize`.
Expand Down