Skip to content

domsec/jpeg-autorotate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logo

Build Status Maven Central with version prefix filter javadoc

JPEG Autorotate is a Java library to rotate JPEG images based on EXIF orientation.


Features

Applies the right orientation to a JPEG image, based on its EXIF tag. More precisely, it:

  • Rotates the pixels
  • Rotates the thumbnail, if present
  • Sets the Orientation EXIF tag to 1 (default orientation value)
  • Updates the following metadata values, if present:
    • EXIF
      • ExifImageWidth
      • ExifImageLength
      • RelatedImageWidth
      • RelatedImageHeight
    • XMP
      • tiff:Orientation
      • tiff:ImageWidth
      • tiff:ImageLength
      • exif:PixelXDimension
      • exif:PixelYDimension
      • xmp:ThumbnailsWidth
      • xmp:ThumbnailsHeight
  • Retains and does not alter other metadata tags
  • Currently does not support updating MakerNotes metadata

More information about EXIF metadata is available at:

Installation

Requires Java 8 or later

You can download source from the releases page

Alternatively, you can install the library via its Maven package

<dependency>
    <groupId>com.domenicseccareccia</groupId>
    <artifactId>jpeg-autorotate</artifactId>
    <version>1.1.0</version>
</dependency>

Usage

The library will load an image by either a String file path, File or InputStream, apply rotation, update metadata and return the image as a byte array.

File Path

byte[] image = JpegAutorotate.rotate("path/to/directory");

File

byte[] image = JpegAutorotate.rotate(new File("path/to/directory"));

InputStream

byte[] image = JpegAutorotate.rotate(new FileInputStream(new File("path/to/directory")));

Error Handling

The library throws the following exceptions:

  • JpegAutorotateException
  • FileNotFoundException
    • Only thrown if loading image by either a String file path or File)

Contributing

Contributions are welcome and will be fully credited.

See CONTRIBUTING.md for information on how to contribute to JPEG Autorotate.

Credits

Libraries

This library uses the following libraries:

Logo

The JPEG Autorotate logo uses the following icons from Font Awesome, available under the Creative Commons Attribution 4.0 International License:

The following icon changes were made:

  • Stroke width decreased for all icons by 0.25
  • Detached arrows from sync-alt

Other

License

This code is under the Apache License v2