ahmedsomaa / sharpixi

An awesome image processing api built with Node.js, TypeScript & Sharp.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sharpixi

An awesome image processing api built with Node.js, TypeScript & Sharp.


Tech Stack

  • Node.js & Express for building the API server.
  • Handlebars as the default view engine.
  • Sharp for image processing.
  • Bootstrap for styling.

Architecture

diagram

Run locally

  • Install dependencies npm install.

  • Run npm run build to create a production build.

  • Rename .env.example to .env file and provide a value for PORT.

  • Run npm run start to start the server.

  • Open you browser and navigate to http://localhost:<PORT>/ to see the resizer page.

Unit tests

The tests are written in jasmine. To run the tests: npm run build && npm run test.

Coverage

  • Express App Tests Suit
    • Serve Favicon
    • Serve Static Files
    • Use Handlebars as view engine
  • Main Router Tests Suit
    • Return 200
    • Return html document
  • Image Router Tests Suit
    • GET /api/{resize | convert} Requests
      • Return 400 for empty query string
      • Return 422 for invalid query string
      • Return 404 if image does not exist
      • Return 200 with resized image for valid query string
      • Return 200 with resized image for the same query string
  • Image Helper Tests Suit
    • imageExists method
      • Return file name with extension if file exists in directory
      • Return "File does not exist" if file does not exist in directory
    • getAllImages method
      • Return a list of 5 images
    • resolveImageDirectoryPath method
      • Return directory full path as string
    • resolveToSourceAndTarget method
      • Return an object with source & target keys
  • Sharp Service Tests Suit
    • resize service
      • Should delete the resized file if exists & create a new fresh one
      • Return "File does not exist" if file does not exist in directory
    • convert service
      • Should delete the resized file if exists & create a new fresh one

Available Scripts

  • dev: to start the development server
  • start: to start the production server
  • test: to run jasmine tests on production build
  • lint: to run eslint on the project's typescript files
  • clean: to remove old builds before building a new one
  • lint:fix: to fix issues identified by eslint
  • postbuild: to copy views folder to the production build folder.
  • format: to run prettier on the project's typescript files

Available APIs

  • /api/resize to resize an image with a given query string for example ?filename=fjord&width=200&height=600.

  • /api/convert to convert an image with a given query string to the given format for example ?filename=fjord&format=png. Supported conversion types are [jpg, png, avif, jpeg, webp].

  • /{full | thumbs}/{image_name} to serve static image files for example /full/fjord.jpg.

Demo

demo.mp4

About

An awesome image processing api built with Node.js, TypeScript & Sharp.


Languages

Language:TypeScript 67.9%Language:Handlebars 29.8%Language:JavaScript 2.2%