imgsquash
imgsquash copied to clipboard
Simple image compression full website code written in node, react and next.js framework. Easy to deploy as a microservice.
SUMMARY
Image compression full stack website code. Contains both api service and frontend written in node, react and next.js framework.
SCREENSHOTS

SETTING UP GOOGLE CLOUD STORAGE
- Create a project on google cloud and add a free cloud storage bucket via this quickstart guide:
- Authenticate using either
gcloudcommand line tool (download here) or setGOOGLE_APPLICATION_CREDENTIALSenv variable with the service account file.- Guide here: https://cloud.google.com/sdk/docs/authorizing
STARTING THE API SERVICE
- Create
.envfile in the root of the folder with the following variables. See dotenv on how to add env variables.- API_VERSION :
1(optional). - GC_STORAGE :
your-google-cloud-bucket-name - DL_BASE_URL :
[YOUR-API-URL]/1/dl
- API_VERSION :
- Do
npm installto install all node modules for api. - Do
npm run devto start the dev server on3000port. - Do
npm startfor production
STARTING THE FRONTEND
- Do
npm installto install all node modules for frontend. - Do
npm run devwill start the webpack server on3001port. - Do
npm run buildandnpm startto build and use the code in production.
NOTES
-
Following programs are used for optimization
- mozjpeg (lossy jpeg compression)
- jpegtran (lossless jpeg compression)
- pngquant (lossy png compression)
- optipng (lossless png compression)
-
Current file size upload limit is 10MB.
-
API Routes. [POST]
/image: upload image(s) via file, URL, base64 or Binary.- file:
fileorbase64orbinary. - lossy:
Boolean(default: false)
- file:
/url: Compression direct image url.- url: valid image url.
/zip: Accepts list of files object as an array with (id,sizeandname) and send the zipped result.- files: list of files object as an array.
[GET] -
/dl/:id: Generate download url of compressed image. Accept optional queryname.
LICENSE
MIT