Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions source/image-handler/test/test-thumbor-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ describe('process()', function() {
thumborMapping.process(event);
// Assert
const expectedResult = {
edits: {
edits: {
grayscale: true,
resize: {
width: 200,
height: 300
height: 300,
},
grayscale: true
}
};
assert.deepEqual(thumborMapping.edits, expectedResult.edits);
Expand Down
29 changes: 19 additions & 10 deletions source/image-handler/thumbor-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,35 @@ class ThumborMapping {
this.path = event.path;
const edits = this.path.split('/');
const filetype = (this.path.split('.'))[(this.path.split('.')).length - 1];
//Process the dimensions of the image
const dimPath = this.path.match(/[^\/]\d+x\d+/g);
if (dimPath) {
const dims = dimPath[0].split('x');
// Set only if the dimensions provided are valid
if (isNaN(dims[0]) == false && isNaN(dims[1]) == false) {
this.edits.resize = {};
// Assign dimenions from the first match only to avoid parsing dimension from image file names
this.edits.resize.width = Number(dims[0]);
this.edits.resize.height = Number(dims[1]);

}
}
// Parse the image path
for (let i = 0; i < edits.length; i++) {
const edit = edits[i];
if (edit === ('fit-in')) {
this.edits.resize = {};
if (this.edits.resize === undefined) {
this.edits.resize = {};
}
this.sizingMethod = edit;
}
else if (edit.includes('x')) {
this.edits.resize = {};
const dims = edit.split('x');
this.edits.resize.width = Number(dims[0]);
this.edits.resize.height = Number(dims[1]);
}
if (edit.includes('filters:')) {
}
else if (edit.includes('filters:')) {
this.mapFilter(edit, filetype);
}
}
return this;
}

/**
* Enables users to migrate their current image request model to the SIH solution,
* without changing their legacy application code to accomodate new image requests.
Expand Down