Skip to content

Commit

Permalink
Restore support for string resize argument "10,10".
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjeffburke committed Aug 25, 2020
1 parent 96f4ab2 commit 35bfdf2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/processOption.js
@@ -1,10 +1,11 @@
const optionConverters = {
resize: value => {
if (!/\d+x\d+/.test(value)) {
const match = value.match(/\d+(x|,)\d+/)
if (match === null) {
throw new Error(`invalid argument for resize ${value}`);
}

const [width, height] = value.split("x");
const [width, height] = value.split(match[1]);

return [parseInt(width, 10), parseInt(height, 10)];
}
Expand Down
27 changes: 26 additions & 1 deletion test/createRightImagePipeline.js
Expand Up @@ -150,7 +150,7 @@ describe("createRightImagePipeline", () => {
);
});

it("should allow a resize option to be supplied as a string", () => {
it("should allow a resize option to be supplied as a string (x)", () => {
const imageFileStream = fs.createReadStream(
path.join(TEST_DATA_PATH, "test.jpg")
);
Expand All @@ -175,6 +175,31 @@ describe("createRightImagePipeline", () => {
});
});

it("should allow a resize option to be supplied as a string (,)", () => {
const imageFileStream = fs.createReadStream(
path.join(TEST_DATA_PATH, "test.jpg")
);

return expect(function(cb) {
createRightImagePipeline(
{
contentType: "image/jpeg",
inputStream: imageFileStream,
imageOptions: {
resize: "30,30"
}
},
cb
);
}, "to call the callback without error").then(([pipelineResult]) => {
const { outputStream, outputTransformed } = pipelineResult;

outputStream.resume();

expect(outputTransformed, "to be true");
});
});

it("should allow no image options to be supplied", () => {
const imageFileStream = fs.createReadStream(
path.join(TEST_DATA_PATH, "tiny.png")
Expand Down

0 comments on commit 35bfdf2

Please sign in to comment.