Image Resizing AWS Lambda using Smartcrop.js
-
Install NVM
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
-
Open new terminal window (To source the new scripts added in .bash_profile) and cd to the root of the project and run
nvm install # this will install the required node version
-
Install node modules
npm install
The project should directly run with default values for the local environment if you need to setup the specific environment variables create a copy of .env.sample with name .env and replace the values.
-
Move to the main directory and make sure correct node version is active.
nvm use
-
Start the server
node server.js
-
Add one of the images in the input folder with a name/directory 'abc/xyz.jpeg'
-
This can be cropped and accessed using the url.
images - manipulation localhost:3000/images/size:200x200/extend:b/blur:5.2/type:crop/xyz.jpeg localhost:<port>/images/size:<Width>x<Height>/extend:<h/w/b>(optional)/blur:<0.3 - 1000>(optional)/auto_rotate:<true/false>(optional)/type:<crop/cover/blurredframe>/<path> fetching raw files localhost:3000/raw/xyz.jpeg localhost:<port>/raw/<path>
-
Url dissection parameters
1. processor - image / raw for now Processor parameter defines the way you want to process my file. 2. size - <Width>x<Height> Size parameter is the required dimensions with which you want to process my file. You can also input one of the two ie width eg. (100x) or height eg. (x100). 3. extend - (h/w/b) Extend parameter defines the dimensions in which you want to extend your image ie. h for height, w for width and b for base. Its an optional parameter and if not provided the image would not be enlarged above its natural size. 4. blur - number between 0.3 - 1000 Blur parameter defines the blur radius with which you want to blur your image. Its also an optional parameter. 5. auto_rotate - (true/false) auto_rotate parameter defines whether you want to apply auto rotate the image. Its default value is true. 6. type - crop/cover/blurredframe Type parameter defines the type of image processing we want to do with our image. This is a required parameter. 7. path The path of your file.