1.0.4 • Published 3 years ago

bibi-image-reducer v1.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Bibi Image Reducer

Reducer, Resize and Format image .JPG, .JPEG and .PNG to be used in projects that use Multer. npm version

Installation

Requires Multer to run.

Install the dependencies and devDependencies and start the server.

yarn add bibi-image-reducer

Comments

It is recommended to create a file with the destination of the folder that the multer uses to save the files.

import path from 'path';

export default path.resolve(__dirname, '..', '..', 'tmp');

Methods

imageReducerInRouter

To use in router to upload.

import imageDestination from 'config/imageDestination';
import { imageReducerInRouter } from 'bibi-image-reducer';

const upload = multer(uploadConfig);

filesRouter.post(
  '/',
  upload.single('file'),
  imageReducerInRouter(imageDestination, 60),
  filesController.create,
);

// or

filesRouter.post(
  '/',
  upload.single('file'),
  imageReducerInRouter(imageDestination, 60, 1500),
  filesController.create,
);

// or

filesRouter.post(
  '/',
  upload.single('file'),
  imageReducerInRouter(imageDestination, 60, {width: 500, height: 800}),
  filesController.create,
);
Params

NameTypeRequired
destinationstringyes
qualitystringyes
resizeobject or numberno

imageReducer

To use in code.

import { imageReducer } from 'bibi-image-reducer'
import imageDestination from 'config/imageDestination';

class FilesController {
  public async create(request: Request, response: Response) {
    await imageReducer(request.file, imageDestination, 50)
    ...
Params

NameTypeRequired
filefileyes
destinationstringyes
qualitystringyes
resizeobject or numberno