1.1.4 • Published 4 years ago

image-mod v1.1.4

Weekly downloads
8
License
MIT
Repository
github
Last release
4 years ago

ImageMod

ImageMod is a lightweight package to compress and convert the image to jpeg/png format

Features

  • support for image
  • support for conversion of image to jpeg/png format
  • support for image compression

Installation

npm install image-mod --save

Usage

use image-mod after the image is being uploaded from any file upload middlewares like multer or express-fileupload. image-mod replaces the uploaded image with modified image and returns its absolute path

Example

const ImageMod = require('image-mod');
//...
const options = {
    file: req.file, //required
    imageType: 'jpeg', //optional
    imageQuality: 50, //optional
};
//...
ImageMod(options).then((filePath) => {
    //filePath is the absolute path of the modified image
});

working example using express and multer

const express = require('express');
const multer = require('multer');
const ImageMod = require('image-mod');
const path = require('path');
const app = express();

const upload = multer({ dest: path.join(__dirname, '/uploads') });

app.post('/upload', upload.single('picture'), async (req, res) => {
    const options = {
        file: req.file,
        imageType: 'png',
        imageQuality: 50,
    };
    const filePath = await ImageMod(options);
    return res.status(200).json({ success: true, filePath });
});

const PORT = 5000;
app.listen(5000, () => {
    console.log('server is running on port ' + PORT);
});

Option

keytyperequirementdefaultvalues
fileFilerequirednull
imageTypeStringoptionaljpegjpeg or png
imageQualityNumberoptional501-100

Contributing

Pull requests are welcome.

License

MIT

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago