1.0.4 • Published 5 years ago
bibi-image-reducer v1.0.4
Bibi Image Reducer
Reducer, Resize and Format image .JPG, .JPEG and .PNG to be used in projects that use Multer.
Installation
Requires Multer to run.
Install the dependencies and devDependencies and start the server.
yarn add bibi-image-reducerComments
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
| Name | Type | Required |
|---|---|---|
| destination | string | yes |
| quality | string | yes |
| resize | object or number | no |
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
| Name | Type | Required |
|---|---|---|
| file | file | yes |
| destination | string | yes |
| quality | string | yes |
| resize | object or number | no |