Installations
npm install jpeg-autorotate
Releases
Unable to fetch releases
Developer
Developer Guide
Module System
CommonJS
Min. Node Version
>=14
Typescript Support
No
Node Version
16.15.0
NPM Version
8.5.5
Statistics
166 Stars
116 Commits
15 Forks
7 Watching
1 Branches
4 Contributors
Updated on 05 Nov 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
6,204,647
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
A node module to rotate JPEG images based on EXIF orientation.
What does it do
This module applies the right orientation to a JPEG image, based on its EXIF tag. More precisely, it:
- Rotates the pixels
- Rotates the thumbnail, if there is one
- Writes
1
in theOrientation
EXIF tag (this is the default orientation) - Updates the
PixelXDimension
andPixelYDimension
EXIF values - Does not alter the other EXIF tags
It may be useful, if:
- You need to compress your image with a tool that strips EXIF data without rotating the pixels (like the great ImageOptim)
- You need to upload the image, but the destination application does not support EXIF orientation (like WordPress)
- You just want to get rid of the orientation tag, while leaving the other tags intact
More information about EXIF:
Installation
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
Usage
Options
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) |
CLI
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
Node module
The Node module will load the image, apply the rotation, and return the binary data as a Buffer, allowing you to:
Sample usage
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 })
Error handling
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 })
Troubleshooting
Thumbnail too large
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}
Changelog
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 |
License
This project is released under the MIT License.
Contributing
Bug reports and feature requests are welcome! More details in the contribution guidelines.
Credits
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: license.md:0
- Info: FSF or OSI recognized license: MIT License: license.md:0
Reason
6 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/johansatge/jpeg-autorotate/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/johansatge/jpeg-autorotate/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/johansatge/jpeg-autorotate/test.yml/master?enable=pin
- Info: 0 out of 3 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
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
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 14 are checked with a SAST tool
Score
3
/10
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