@artdotstyle/filepix

1.0.11 • Public • Published

FilePix

npm building workflow

powerful image converter package, it can convert images into a different formats, it includes below features:


Installation

Install via NPM:

npm install filepix

Then you can require or import as usual:

const filepix = require("filepix");
import * as filepix from "filepix";

Convert images to PDF

this feature let you convert your images into a single pdf file

Basic Usage

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 effects

add easily a lot of effect to your images while converting to pdf

add effect to your final pdf by set some options.

Color

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

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);

Blur

A fast blur algorithm that produces similar effect to a Gaussian blur

let options = {
   effects: [
              {
                name: 'blur',
                config: {
                    pixels: 50
                }
              }
            ]
  };

Rotate

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
                }
              }
            ]
};

Brightness

let options = {
   effects: [
              {
                name: 'brightness',
                config: {
                    ratio: 0.1
                }
              }
            ]
};

Contrast

let options = {
   effects: [
              {
                name: 'contrast',
                config: {
                    ratio: 0.2
                }
              }
            ]
  };

Gaussian

let options = {
   effects: [
              {
                name: 'gaussian',
                config: {
                    ratio: 2
                }
              }
            ]
};

Posterize

let options = {
   effects: [
              {
                name: 'posterize',
                config: {
                    ratio: 100
                }
              }
            ]
};

Opacity

let options = {
   effects: [
              {
                name: 'opacity',
                config: {
                    ratio: 0.1
                }
              }
            ]
};

Sepia

let options = {
   effects: [
              {
                name: 'sepia'
              }
            ]
};

Quality

let options = {
   effects: [
              {
                name: 'quality',
                config: {
                    ratio: 10
                }
              }
            ]
};

Fade

let options = {
   effects: [
              {
                name: 'fade',
                config: {
                    ratio: 0.1
                }
              }
            ]
};

Pixelate

let options = {
   effects: [
              {
                name: 'pixelate',
                config: {
                    ratio: 50
                }
              }
            ]
};

Normalize

let options = {
   effects: [
              {
                name: 'normalize',
                config: {
                    ratio: 50
                }
              }
            ]
};

Threshold

let options = {
   effects: [
              {
                name: 'threshold',
                config: { max: 200, replace: 200, autoGreyscale: false }
              }
            ]
};

multiple effects

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 }
            }
          ]
};

Add watermarks

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'
  }
}

Convert pdf to images

this feature let you convert your pdf into multiple images.

Basic Usage

filepix.PDF2img('./inputImagesDir/input.pdf', "./outputImageDir");

Convert pdf to word document

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');

Custom Language

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 to jpg

convert png format into jpg even you can compress your image.

await filepix.png2jpeg('./input.png', './output.jpg'
, options = {
  quality: 50
});

base64 to jpg or png

convert base64 to png or jpg by calling below method.

await filepix.base64ToImg('base64Str', './outputImageDir/output.png', { extension: 'png' });

Support

Contributors

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.

License

This project is licensed under the terms of the MIT license

Package Sidebar

Install

npm i @artdotstyle/filepix

Weekly Downloads

3

Version

1.0.11

License

MIT

Unpacked Size

114 kB

Total Files

18

Last publish

Collaborators

  • ciprianigna