Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jpeg-autorotate

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jpeg-autorotate

Rotates JPEG images based on EXIF orientation

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12K
decreased by-31.29%
Maintainers
1
Weekly downloads
 
Created
Source

Version Downloads Dependencies devDependencies

Icon

Rotates JPEG images based on EXIF orientation.


  • What does it do
  • Installation
  • Usage
  • Changelog
  • License
  • Credits

What does it do

This tool 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 the Orientation EXIF tag (this is the default orientation)
  • Updates the PixelXDimension and PixelYDimension 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 orientation: EXIF Orientation Handling Is a Ghetto

Installation

Install with npm:

$ npm install jpeg-autorotate --global
# --global isn't required if you plan to use the node module

Usage

CLI

# Rotates a single image
$ jpeg-autorotate /Users/johan/IMG_1234.jpg
# Rotates a set of images
$ jpeg-autorotate /Users/johan/images/IMG_*.jpg

Node module

The tool is available as a Node module. It will load the image, apply the rotation, and return the binary data as a Buffer, allowing you to:

  • Save it on disk
  • Load it in an image processing module (like jimp, lwip, gm...)
  • ...
Sample usage
var jpegautorotate = require('jpeg-autorotate');
var options = {quality: 85};
jpegautorotate.rotate('/Users/johan/IMG_1234.jpg', options, function(error, buffer, orientation)
{
    if (error)
    {
        console.log('An error occurred when rotating the file: ' + error.message);
        return;
    }
    console.log('Orientation was: ' + orientation);
    // ...
    // Do whatever you need with the buffer
    // ...
});
Error handling

The error object returned in the callback contains a readable message, but also a code for better error handling. Available codes are the following:

var jo = require('jpeg-autorotate');

jo.errors.read_file; // File could not be opened
jo.errors.read_exif; // EXIF data could not be read
jo.errors.no_orientation; // No orientation tag was found
jo.errors.unknown_orientation; // The orientation tag is unknown
jo.errors.correct_orientation; // The image orientation is already correct
jo.errors.rotate_file; // An error occurred when rotating the image

Sample usage:

var jo = require('jpeg-autorotate');
jo.rotate('/image.jpg', function(error, buffer, orientation)
{
    if (error && error.code === jo.errors.correct_orientation)
    {
        console.log('The orientation of this image is already correct!');
    }
});

Options

The following options are available.

OptionContextDefault valueDescription
qualityCLI, module100Quality of the JPEG - Uncompressed by default, so the resulting image may be bigger than the original one
jobsCLI10Max number of concurrent processes, when loading several images

To use options with the CLI:

$ jpeg-autorotate /image.jpg --jobs=100 --quality=85

Changelog

This project uses semver.

VersionDateNotes
1.0.02016-03-21Initial version

License

This project is released under the MIT License.

Credits

Keywords

FAQs

Package last updated on 21 Mar 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc