domsec / jpeg-autorotate Goto Github PK
View Code? Open in Web Editor NEWA Java library to rotate JPEG images based on EXIF orientation
License: Apache License 2.0
A Java library to rotate JPEG images based on EXIF orientation
License: Apache License 2.0
When a JPEG image does not have a valid EXIF orientation metadata tag value (1 to 8), the exception message thrown does not include the orientation value contained inside the metadata tag. As such, there is lose of information for the error related to the image EXIF metadata.
Change the exception message as follows:
Location: JpegImageTransform.rotateAndFlip()`
Old Message: "JPEG image has an unknown EXIF Orientation metadata tag."
New Message: "JPEG image has an unknown EXIF Orientation metadata tag value: " + orientation
Currently when getting a JPEG image BufferedImage
from a byte array, temporary files are being created, read and subsequently deleted. As such, we are creating unnecessary I/O operations (write, read and delete) that could be avoided while also avoiding potential file system permissions problems.
Describe the solution you'd like
Obtain the BufferedImage
by reading the byte array using a ByteArrayInputStream
. This in turn would both drastically improve performance and reduce the total number of I/O operations.
Such an implementation would have avoided #10 .
Describe alternatives you've considered
N/A
Additional context
Such a refactor must also be done in the respective test cases.
<version></version>
in pom.xml
to 1.0.0
mvn clean deploy
After project is released in Maven Central repository
README.md
version
to 1.0.0
in Installationmaven-central
badge linkjavadoc
badge linkjar
with dependencies in Maven mvn clean compile assembly:single
.zip
and tar.gz
v1.0.0
jar
with dependencies.zip
and tar.gz
Executed following command in command prompt: mvn versions:display-dependency-updates
The following dependencies in Dependencies have newer versions:
[INFO] commons-io:commons-io ................................... 2.6 -> 2.8.0
[INFO] org.apache.commons:commons-imaging .......... 1.0-alpha1 -> 1.0-alpha2
[INFO] org.junit.jupiter:junit-jupiter-api ................... 5.5.2 -> 5.7.0
[INFO] org.junit.jupiter:junit-jupiter-engine ................ 5.5.2 -> 5.7.0
If a non JPEG file (i.e. .png, .doc, .pdf) were to have its extension changed either programically or manually before being passed as a parameter - path or file - to the library, said file will not be rejected as a non JPEG file. As such, the file will be processed instead of being rejected and throwing an exception.
.png
to .jpg
(i.e. blue_box.jpg
)ImageUtilsTest
class, change the PNG_IMAGE
string value from "src/test/resources/blue_box.png"
to "src/test/resources/blue_box.jpg"
ImageUtilsTest.testIsJpeg()
test caseAny non JPEG file where the file extension changes programically or manually before processing by the library should be rejected during initial file type validation and subsequently throw a corresponding exception.
As such, ImageUtilsTest.testIsJpeg()
does not fail as the non JPEG image after having its extension manually changed gets rejected.
Non JPEG images with manually changed extensions to .jpg
are not being rejected and subsequently continue to be processed by the library only to get rejected later on when updating the associated metadata.
When doing such a change to a non JPEG file and then running the ImageUtilsTest.testIsJpeg()
test case, it fails.
N/A
<version></version>
in pom.xml
to 1.1.0
mvn clean deploy
After project is released in Maven Central repository
README.md
version
to 1.1.0
in Installationmaven-central
badge linkjavadoc
badge linkjar
with dependencies in Maven mvn clean compile assembly:single
v1.1.0
jar
with dependenciesDescribe the bug
Temp files are not deleted during application runtime, even after they will no longer be used again.
This causes full copies of the every rotated file to be stored in a temporary folder never to be deleted until the application closes. Potentially is causing problems with ethereal storage limits on kubernetes pods that restart/evict pod when using too much temporary disk usage.
Expected behavior
Temp files that are no longer used are cleaned up/deleted.
JPEG image files
All files
Update all copyright across all code to Copyright (c) 2019-2021
Automatically rotate a JPEG image file to the correct orientation based on the EXIF Orientation
tag.
Component | Description |
---|---|
Image | - If metadata Orientation EXIF tag does not equal 1 then rotate to correct orientation - If metadata Orientation EXIF tag equals 1 then do NOT rotate image |
Input | - Single image file at a time - Directory is NOT supported - java.io.File - String file path - InputStream Supported File Types: - jpg - jpeg - JPG - JPEG |
Output | byte[] |
Metadata | - Update if image is rotated Update: - Orientation EXIF tag = 1 - ExifImageWidth EXIF tag - ExifImageLength EXIF tag- ImageWidth File tag - ImageHeight File tag - XMP metadata - Remaining metadata must not be altered (ICC Profile, Photoshop, etc) |
Thumbnail | - If present then rotate to correct orientation - Rotation based on metadata Orientation EXIF tag not equaling 1 |
Hi,
With some jpegs, I am seeing this, and not sure of the best way to check for the details.
com.domenicseccareccia.jpegautorotate.JpegAutorotateException: Unable to read JPEG image EXIF Image Width and/or Image Height metadata tags.
thanks
It fails on NullPointerException while processing some (any image from Pixel 6 Pro) images, here is the stack trace:
Caused by: java.lang.NullPointerException: Cannot invoke "[B.clone()" because "this.iccBytes" is null at org.apache.commons.imaging.formats.jpeg.segments.App2Segment.getIccBytes(App2Segment.java:90) at org.apache.commons.imaging.formats.jpeg.JpegImageParser.getICCProfileBytes(JpegImageParser.java:295) at org.apache.commons.imaging.Imaging.getICCProfileBytes(Imaging.java:545) at org.apache.commons.imaging.Imaging.getICCProfile(Imaging.java:440) at org.apache.commons.imaging.Imaging.getICCProfile(Imaging.java:363) at org.apache.commons.imaging.Imaging.getICCProfile(Imaging.java:345) at com.domenicseccareccia.jpegautorotate.imaging.JpegImageMetadataReader.readIccProfile(JpegImageMetadataReader.java:118) at com.domenicseccareccia.jpegautorotate.imaging.JpegImageMetadata.<init>(JpegImageMetadata.java:55) at com.domenicseccareccia.jpegautorotate.imaging.JpegImage.<init>(JpegImage.java:35) at com.domenicseccareccia.jpegautorotate.imaging.JpegImageProcessor.process(JpegImageProcessor.java:65) at com.domenicseccareccia.jpegautorotate.JpegAutorotate.rotate(JpegAutorotate.java:157)
JPEG image files
If applicable, add jpeg image files causing the error when processed with JPEG Autorotate.
<version></version>
in pom.xml
to 1.0.1
mvn clean deploy
After project is released in Maven Central repository
README.md
version
to 1.0.1
in Installationmaven-central
badge linkjavadoc
badge linkjar
with dependencies in Maven mvn clean compile assembly:single
.zip
and tar.gz
v1.0.0
jar
with dependencies.zip
and tar.gz
Describe the bug
Java streams (i.e. ByteArrayOutputStream
) are either not closed in a finally
block or closed at all.
Affected areas:
Expected behavior
All Java streams no longer in use are to be closed within either a finally
or try-with-resources
block.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.