Gathering detailed insights and metrics for jpeg-autorotate
Gathering detailed insights and metrics for jpeg-autorotate
Gathering detailed insights and metrics for jpeg-autorotate
Gathering detailed insights and metrics for jpeg-autorotate
npm install jpeg-autorotate
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
166 Stars
116 Commits
15 Forks
7 Watching
1 Branches
4 Contributors
Updated on 05 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
4.7%
3,071
Compared to previous day
Last week
6%
16,650
Compared to previous week
Last month
-6.8%
69,901
Compared to previous month
Last year
-29.6%
891,132
Compared to previous year
A node module to rotate JPEG images based on EXIF orientation.
This module applies the right orientation to a JPEG image, based on its EXIF tag. More precisely, it:
1
in the Orientation
EXIF tag (this is the default orientation)PixelXDimension
and PixelYDimension
EXIF valuesIt may be useful, if:
More information about EXIF:
This module needs Node >=14
.
Install with npm:
1$ npm install jpeg-autorotate --global 2# --global isn't required if you plan to use the node module
Option | Default value | Description |
---|---|---|
quality | 100 | Quality of the JPEG. Uncompressed by default, so the resulting image may be bigger than the original one. |
jpegjsMaxResolutionInMP | jpeg-js default | maxResolutionInMP option in jpeg-js (doc) |
jpegjsMaxMemoryUsageInMB | jpeg-js default | maxMemoryUsageInMB option in jpeg-js (doc) |
Rotate a single image:
1$ jpeg-autorotate /Users/johan/IMG_1234.jpg
Rotate a set of images:
1$ jpeg-autorotate /Users/johan/images/IMG_*.jpg
Glob support:
1$ jpeg-autorotate "/Users/johan/images/IMG_*.{jpg,jpeg,JPG,JPEG}"
Passing options:
$ jpeg-autorotate /Users/johan/IMG_1234.jpg --quality=85 --jpegjsMaxResolutionInMP=1234
The Node module will load the image, apply the rotation, and return the binary data as a Buffer, allowing you to:
1const jo = require('jpeg-autorotate') 2const options = { 3 quality: 8, 4 jpegjsMaxResolutionInMP: 1234, 5} 6const path = '/Users/johan/IMG_1234.jpg' // You can use a Buffer too 7 8// 9// With a callback: 10// 11jo.rotate(path, options, (error, buffer, orientation, dimensions, quality) => { 12 if (error) { 13 console.log('An error occurred when rotating the file: ' + error.message) 14 return 15 } 16 console.log(`Orientation was ${orientation}`) 17 console.log(`Dimensions after rotation: ${dimensions.width}x${dimensions.height}`) 18 console.log(`Quality: ${quality}`) 19 // ...Do whatever you need with the resulting buffer... 20}) 21 22// 23// With a Promise: 24// 25jo.rotate(path, options) 26 .then(({buffer, orientation, dimensions, quality}) => { 27 console.log(`Orientation was ${orientation}`) 28 console.log(`Dimensions after rotation: ${dimensions.width}x${dimensions.height}`) 29 console.log(`Quality: ${quality}`) 30 // ...Do whatever you need with the resulting buffer... 31 }) 32 .catch((error) => { 33 console.log('An error occurred when rotating the file: ' + error.message) 34 })
The error
object returned by the module contains a readable message
, but also a code
for better error handling. Available codes are the following:
1const jo = require('jpeg-autorotate') 2 3jo.errors.read_file // File could not be opened 4jo.errors.read_exif // EXIF data could not be read 5jo.errors.no_orientation // No orientation tag was found 6jo.errors.unknown_orientation // The orientation tag is unknown 7jo.errors.correct_orientation // The image orientation is already correct 8jo.errors.rotate_file // An error occurred when rotating the image
Example:
1const jo = require('jpeg-autorotate') 2jo.rotate('/image.jpg') 3 .catch((error) => { 4 if (error.code === jo.errors.correct_orientation) { 5 console.log('The orientation of this image is already correct!') 6 } 7 })
The piexifjs module has a 64kb limit when reading thumbnails. If you get the Given thumbnail is too large error, you can try to remove the thumbnail from the image before rotating it:
1import piexif from 'piexifjs' 2 3function deleteThumbnailFromExif(imageBuffer) { 4 const imageString = imageBuffer.toString('binary') 5 const exifObj = piexif.load(imageString) 6 delete exifObj['thumbnail'] 7 delete exifObj['1st'] 8 const exifBytes = piexif.dump(exifObj) 9 return Buffer.from(piexif.insert(exifBytes, imageString), 'binary') 10}
This project uses semver.
Version | Date | Notes |
---|---|---|
9.0.0 | 2023-02-11 | Drop Node 12 support |
8.0.1 | 2022-01-10 | Remove colors package from dependencies |
8.0.0 | 2021-11-12 | Node 16 support Drop support for Node 10 |
7.1.1 | 2020-10-11 | Introduce code coverage Fix an error if options are not passed |
7.1.0 | 2020-10-10 | Introduce jpegjsMaxResolutionInMP & jpegjsMaxMemoryUsageInMB options (#26) |
7.0.0 | 2020-09-19 | Don't publish test and linting files on NPM |
6.0.0 | 2020-05-30 | Dependencies update Drop support for Node < 10 From jpeg-js update: images larger than 100 megapixels or requiring more than 512MB of memory to decode will throw |
5.0.3 | 2019-12-24 | Fix multiple file support in CLI Dependencies update |
5.0.2 | 2019-09-28 | Dependencies update |
5.0.1 | 2019-06-08 | Fix CLI support |
5.0.0 | 2019-03-03 | Drop --jobs CLI optionDrop support for Node 6 & 7 Introduce new quality property in the jo.rotate callbackPublic API now supports both callbacks and Promises Update documentation accordingly Update dependencies |
4.0.1 | 2018-11-29 | Fix rotations 5 and 7 (issue #11) |
4.0.0 | 2018-07-15 | Drop support for Node 4 & 5 Unpublish lockfile Use prettier for code formatting Update documentation Update dependencies |
3.1.0 | 2017-12-03 | Output dimensions after rotation |
3.0.1 | 2017-07-30 | Node 8 support Update dependencies |
3.0.0 | 2017-02-11 | CLI supports glob No more node 0.12 supportDrop semicolons Add eslint rules |
2.0.0 | 2016-06-03 | Supports buffers in entry Returns a buffer even if there was an error Improves tests |
1.1.0 | 2016-04-23 | Adds test suite, removes lwip dependency |
1.0.3 | 2016-03-29 | Displays help when no path given in CLI |
1.0.2 | 2016-03-21 | Adds missing options in CLI help |
1.0.1 | 2016-03-21 | Fixes NPM publishing fail ^_^ |
1.0.0 | 2016-03-21 | Initial version |
This project is released under the MIT License.
Bug reports and feature requests are welcome! More details in the contribution guidelines.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
6 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/23 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More