Reducer, Resize and Format image .JPG, .JPEG and .PNG to be used in projects that use Multer.
Requires Multer to run.
Install the dependencies and devDependencies and start the server.
yarn add bibi-image-reducer
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');
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,
);
Name | Type | Required |
---|---|---|
destination | string | yes |
quality | string | yes |
resize | object or number | no |
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)
...
Name | Type | Required |
---|---|---|
file | file | yes |
destination | string | yes |
quality | string | yes |
resize | object or number | no |