From 71f3b92c3f886b5034f2a7acf705b1b3d67ad35e Mon Sep 17 00:00:00 2001 From: Sagid M Date: Tue, 5 Feb 2019 23:10:12 +0300 Subject: [PATCH] Revert "Fix for files that are rotated after resizing (#1)" This reverts commit 39d4cefc8dc779202147c432b46d32a66849de45. --- .gitignore | 1 - README.md | 2 +- index.js | 50 +++++++++++++++++++------------------------------- package.json | 2 +- 4 files changed, 21 insertions(+), 34 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 30bc162..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/node_modules \ No newline at end of file diff --git a/README.md b/README.md index 8716d42..79d06a1 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ or * * * In **Security** select **Open**, then click **Next** * * In **Configure function** page * * * Name a new lambda -* * * In **Runtime** select **Node.js 8.10** +* * * In **Runtime** select **Node.js 6.10** * * * Upload a _.zip_ file (download it from [releases](https://github.com/sagidM/s3-resizer/releases)) * * * > You'll also need to set up two **Environment variables**, with _BUCKET_ and _URL_ as keys. But in this time, you don't know about that _URL_. It is **endpoint** which you'll see below. * * * Choose role which has permission to put any object or create a new one. To do that diff --git a/index.js b/index.js index 1a405f6..878c739 100644 --- a/index.js +++ b/index.js @@ -19,45 +19,33 @@ exports.handler = function(event, _context, callback) { var sizes = options[0].split("x"); - var action = options.length > 1 ? options[1] : null; - - if (action && action !== 'max' && action !== 'min') { - callback(null, { - statusCode: 400, - body: `Unknown func parameter "${action}"\n` + - 'For query ".../150x150_func", "_func" must be either empty, "_min" or "_max"', - headers: {"Content-Type": "text/plain"} - }); - return; - } + var func = options.length > 1 ? options[1] : null; var contentType; S3.getObject({Bucket: BUCKET, Key: dir + filename}) .promise() .then(data => { contentType = data.ContentType; - var width = sizes[0] === 'AUTO' ? null : parseInt(sizes[0]); - var height = sizes[1] === 'AUTO' ? null : parseInt(sizes[1]); - var fit; - switch (action) { - case 'max': - fit = 'inside'; - break; - case 'min': - fit = 'outside'; - break + var img = Sharp(data.Body) + .resize( + sizes[0] === 'AUTO' ? null : parseInt(sizes[0]), + sizes[1] === 'AUTO' ? null : parseInt(sizes[1])); + + switch (func){ + case 'max': img = img.max(); break; + case 'min': img = img.min(); break; + case null: break; default: - fit = 'cover'; - break; + callback(null, { + statusCode: 400, + body: `Unknown func parameter "${func}"\n` + + 'For query ".../150x150_func", "_func" must be either empty, "_min" or "_max"', + headers: {"Content-Type": "text/plain"} + }) + return new Promise(() => {}) // the next then-blocks will never be executed } - var options = { - withoutEnlargement: true, - fit - }; - return Sharp(data.Body) - .resize(width, height, options) - .rotate() - .toBuffer(); + + return img.withoutEnlargement().toBuffer(); }) .then(result => S3.putObject({ diff --git a/package.json b/package.json index 230195e..527c34f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "s3-resizer", "version": "2.0.0", "dependencies": { - "sharp": "^0.21.3" + "sharp": "^0.20.1" }, "devDependencies": { "aws-sdk": "^2.36.0"