powerful image converter package, it can convert images into a different formats, it includes below features:
- convert pdf to word document
- convert images into a single pdf file
- convert pdf to multiple image file
- convert png to jpg
- convert base64 to jpg or png
- compress image files
- add watermarks or extra effects to your image files
Install via NPM:
npm install filepix
Then you can require or import as usual:
const filepix = require("filepix");
import * as filepix from "filepix";
this feature let you convert your images into a single pdf file
if you want to convert all images inside a specific directory you can use below code:
pages
: images directory path
source
: output for saving final PDF file
filepix.img2PDF(pages = './inputImagesDir', output = "./outputImageDir/output.pdf");
or maybe your images file in different path for this case you can use below code:
filepix.img2PDF(
pages = [
'./1.jpg',
'./public/upload/2.jpg',
'./public/upload/example/3.jpg'
],
output = "./outputImageDir/output.pdf");
add easily a lot of effect to your images while converting to pdf
add effect to your final pdf by set some options.Apply multiple color modification rules
let options = {
effects: [
{
name: 'color',
config: [{ apply: 'green', params: [100] }]
}
]
};
filepix.img2PDF(pages = './inputImagesDir', output = "./outputImageDir/output.pdf", options);
Flip the image horizontally or vertically. Defaults to horizontal.
let options = {
effects: [
{
name: 'mirror'
}
]
};
let options = {
effects: [
{
name: 'flip',
config: {
vertical: true
}
}
]
};
filepix.img2PDF(pages = './inputImagesDir', output = "./outputImageDir/output.pdf", options);
A fast blur algorithm that produces similar effect to a Gaussian blur
let options = {
effects: [
{
name: 'blur',
config: {
pixels: 50
}
}
]
};
Rotates the image clockwise by a number of degrees. By default the width and height of the image will be resized appropriately.
let options = {
effects: [
{
name: 'rotate',
config: {
ratio: 45
}
}
]
};
let options = {
effects: [
{
name: 'brightness',
config: {
ratio: 0.1
}
}
]
};
let options = {
effects: [
{
name: 'contrast',
config: {
ratio: 0.2
}
}
]
};
let options = {
effects: [
{
name: 'gaussian',
config: {
ratio: 2
}
}
]
};
let options = {
effects: [
{
name: 'posterize',
config: {
ratio: 100
}
}
]
};
let options = {
effects: [
{
name: 'opacity',
config: {
ratio: 0.1
}
}
]
};
let options = {
effects: [
{
name: 'sepia'
}
]
};
let options = {
effects: [
{
name: 'quality',
config: {
ratio: 10
}
}
]
};
let options = {
effects: [
{
name: 'fade',
config: {
ratio: 0.1
}
}
]
};
let options = {
effects: [
{
name: 'pixelate',
config: {
ratio: 50
}
}
]
};
let options = {
effects: [
{
name: 'normalize',
config: {
ratio: 50
}
}
]
};
let options = {
effects: [
{
name: 'threshold',
config: { max: 200, replace: 200, autoGreyscale: false }
}
]
};
you can combine effects by using below code:
let options = {
effects: [
{
name: 'quality',
config: {
ratio: 10
}
},
{
name: 'contrast',
config: {
ratio: 0.2
}
},
{
name: 'threshold',
config: { max: 200 }
}
]
};
you can add watermark to all images and merge them as single pdf by set below option path: watermark image path position: watermark position (center,right,right-bottom,center-bottom,left-top,left-bottom)
options = {
watermark: {
type: 'image',
path: '../logo1.jpg',
ratio: 0.2,
opacity: 0.2,
position: 'left-bottom'
}
}
this feature let you convert your pdf into multiple images.
filepix.PDF2img('./inputImagesDir/input.pdf', "./outputImageDir");
NOTE: this method using OCR so first, you need to install the Tesseract project. Instructions for installing Tesseract for all platforms can be found on the project site.
after installing Tesseract you can easily convert your pdf into file as docx format by calling below code:
await filepix.pdf2docx('./inputImageDir/input.pdf', './outputImageDir/output.docx');
1- find your LangCode from here 2- download proper .traineddata file from here and copy it on your local machine in Tesseract-OCR/tessdata directory 3- finally use below code:
await filepix.pdf2docx('./inputImageDir/input.pdf', './outputImageDir/output.docx', options = { lang: "deu" });
convert png format into jpg even you can compress your image.
await filepix.png2jpeg('./input.png', './output.jpg'
, options = {
quality: 50
});
convert base64 to png or jpg by calling below method.
await filepix.base64ToImg('base64Str', './outputImageDir/output.png', { extension: 'png' });
Pull requests are always welcome! Please base pull requests against the main branch and follow the contributing guide.
if your pull requests makes documentation changes, please update readme file.
This project is licensed under the terms of the MIT license