Image compression full stack website code. Contains both api service and frontend written in node, react and next.js framework.
- 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
- Create
.envfile in the root of the folder with the following variables.- API_VERSION : 1 (default)
- GC_STORAGE : your-google-cloud-bucket-name
- DL_BASE_URL : [YOUR-API-URL]/1/dl
- Do
npm installto install all node modules. - Do
npm run devto start the dev server on3000port. - Do
npm startfor production
- Do
npm startto install. - Do
npm run devwill start the webpack server on3001port. - Do
npm buildandnpm startto build and use the code in production.
-
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.
MIT