You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

dpi-tools

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dpi-tools

Quickly change the dpi for an image without re-enconding

1.0.7
latest
Source
npmnpm
Version published
Weekly downloads
737
-18.47%
Maintainers
1
Weekly downloads
 
Created
Source

dpi-tools

dpi-tools provides 2 utility functions that can change the dpi of canvas-generated image, of either dataUrl or blob formats. The functions separate the header from the image data, convert and manipulate just the header, then sticks the header back on the file. In this way, very large images can be converted quickly without having to convert the entire contents of an image file. This process is non-destructive—image data does not get modified in the process.

This package is forked from shutterstock/changeDPI in an attempt to modernize the build process using rollup and hopefully implement some new features!

Install

npm install --save dpi-tools

Import

/* ES6 */
import dpiTools from 'dpi-tools';
import { changeDpiDataUrl, changeDpiBlob } from 'dpi-tools';
/* ES5 */
var dpiTools = require('dpi-tools');

Usage

From a canvas element dataUrl:

// create the dataUrl at standard 72dpi
var dataUrl = canvas.toDataURL('image/jpeg', 0.92);
var daurl150dpi = changeDpiDataUrl(dataUrl, 150);

From a canvas element blob:

// create the blob at standard 72dpi
canvas.toBlob(
  function (blob) {
    changeDpiBlob(blob, 300).then(function (blob) {
      // use your changed blob
    });
  },
  'image/jpeg',
  0.92
);
  TODO add example with file reader.

ES6

This module uses ES6. To see a compiled ES5 version, run npm run build and look in dist/.

Testing

npm install
npm run test

Contribute

Please do contribute! Open an issue or submit a pull request.

The project falls under @Shutterstock's Code of Conduct.

License

MIT.

Keywords

dpi

FAQs

Package last updated on 12 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts