An image processing web API that resizes JPG format image. Written in TypeScript Nodejs with Express server, Jasmine for unit testing, and Sharp for image processing. Prettier and ESLint enabled.
URL end point example: http://localhost:3000/api/images?filename=santamonica&width=500&height=500
The query parameters:
- filename: takes only name without .jpg extension.
- width: must be number and greater than 0.
- height: must be number and greater than 0.
- Run
npm run prettierto confirm all files are formatted. - Run
npm run lintto confirm all files are error-free. - Run
npm run startto start the server from the ./src folder. And you should be able to start testing. See testing instructions below. - Run
npm run testto transpile TS files from ./src folder into JS files in ./build folder, and run unit testing scripts. All 28 unit testing cases should be passed. - Run
node build/.to start the server from the ./build folder. And you should be able to start testing again. See testing instructions below.
- Put a full size jpg file into ./images/full folder.
- Update the values of query parameters in the url end point with your filename (no .jpg), your desired resize width and height (must > 0).
- Run the url in the browser. You should be able to view the resized image.
- Check the resized image in ./images/thumb folder if you are resizing the image to this size for the first time.
- Look for file name {original filename}_{width}x{height}.jpg
- Run the same url again. The same thumb image should stay without any modification.
- Try run with different resized width and height for the same file. You should be able to see multiple resized images stored in the thumb folder with respective name.
- If encounter any error, check the file ./debug.log for more information.
- The information about images being processed or accessed is logged in ./debug.log.
- If being accessed, the message is "Resize file exists. Send directly to the response."
- If being processed, the message is "Resize file not found. Resizing and saving to file."