https://github.com/shutterstock/changeDPI
Javascript library that allows you to change an image's DPI settings in the browser
https://github.com/shutterstock/changeDPI
javascript
Last synced: about 1 year ago
JSON representation
Javascript library that allows you to change an image's DPI settings in the browser
- Host: GitHub
- URL: https://github.com/shutterstock/changeDPI
- Owner: shutterstock
- License: mit
- Created: 2018-05-31T16:54:38.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-04-27T08:46:39.000Z (almost 6 years ago)
- Last Synced: 2025-04-05T05:02:12.976Z (about 1 year ago)
- Topics: javascript
- Language: JavaScript
- Homepage:
- Size: 179 KB
- Stars: 234
- Watchers: 6
- Forks: 56
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# changeDPI
changeDPI 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.
## Install
This project depends on [node](https://nodejs.org) and [npm](https://npmjs.com).
```js
npm install --save changedpi
```
## Usage
From a canvas element dataUrl:
```js
// create the dataUrl at standard 72dpi
var dataUrl = canvas.toDataURL('image/jpeg', 0.92);
var daurl150dpi = changeDpiDataUrl(dataUrl, 150);
```
From a canvas element blob:
```js
// create the blob at standard 72dpi
canvas.toBlob(function(blob) {
changeDpiBlob(blob, 300).then(function(blob){
// use your changed blob
})
},'image/jpeg', 0.92);
```
```js
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
```js
npm install .
npm run test
```
## Contribute
Please do contribute! Open an issue or submit a pull request.
The project falls under [@Shutterstock](https://github.com/shutterstock/welcome)'s [Code of Conduct](https://github.com/shutterstock/welcome/blob/master/CODE_OF_CONDUCT.md).
## License
MIT.