summaryrefslogtreecommitdiff
path: root/pdf-over-signator/src/main
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2017-01-09 09:26:07 +0100
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2017-01-09 09:26:07 +0100
commit5c4f6dd07b601992e9afd2d8201a46519e04be2b (patch)
treedef4ba9b5ea4a02a0e65bb1437ff932080ce0c5f /pdf-over-signator/src/main
parente5b15e43c83ce13a64d2238ed80eebd81805c979 (diff)
downloadpdf-over-5c4f6dd07b601992e9afd2d8201a46519e04be2b.tar.gz
pdf-over-5c4f6dd07b601992e9afd2d8201a46519e04be2b.tar.bz2
pdf-over-5c4f6dd07b601992e9afd2d8201a46519e04be2b.zip
Fixed NullPointerException with reading EXIF Metadata for JPEG Files
Diffstat (limited to 'pdf-over-signator/src/main')
-rw-r--r--pdf-over-signator/src/main/java/at/asit/pdfover/signator/CachedFileNameEmblem.java85
1 files changed, 45 insertions, 40 deletions
diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/CachedFileNameEmblem.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/CachedFileNameEmblem.java
index 73f25837..2b70afa3 100644
--- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/CachedFileNameEmblem.java
+++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/CachedFileNameEmblem.java
@@ -101,52 +101,57 @@ public class CachedFileNameEmblem implements Emblem {
if (reader.getFormatName().equals("JPEG")) {
try {
Metadata metadata = ImageMetadataReader.readMetadata(imgFile);
- int orientation = metadata.getFirstDirectoryOfType(
- ExifIFD0Directory.class).getInt(
- ExifDirectoryBase.TAG_ORIENTATION);
- if (orientation > 2) {
- // rotate
- double rotation = 0;
- int height = owidth;
- int width = oheight;
- switch ((orientation + 1) / 2) {
- case 2:
- rotation = Math.PI;
- height = oheight;
- width = owidth;
- break;
- case 3:
- rotation = Math.PI/2;
- break;
- case 4:
- rotation = 3*Math.PI/2;
- break;
+
+ if(metadata != null) {
+ int orientation = metadata.getFirstDirectoryOfType(
+ ExifIFD0Directory.class).getInt(
+ ExifDirectoryBase.TAG_ORIENTATION);
+ if (orientation > 2) {
+ // rotate
+ double rotation = 0;
+ int height = owidth;
+ int width = oheight;
+ switch ((orientation + 1) / 2) {
+ case 2:
+ rotation = Math.PI;
+ height = oheight;
+ width = owidth;
+ break;
+ case 3:
+ rotation = Math.PI / 2;
+ break;
+ case 4:
+ rotation = 3 * Math.PI / 2;
+ break;
+ }
+ log.debug("EXIF orientation " + orientation + ", rotating " + rotation + "rad");
+ BufferedImage result = new BufferedImage(width, height, img.getType());
+ Graphics2D g = result.createGraphics();
+ g.translate((width - owidth) / 2, (height - oheight) / 2);
+ g.rotate(rotation, owidth / 2, oheight / 2);
+ g.drawRenderedImage(img, null);
+ g.dispose();
+ img = result;
+ owidth = width;
+ oheight = height;
+ }
+ if (((orientation < 5) && (orientation % 2 == 0)) ||
+ (orientation > 5) && (orientation % 2 == 1)) {
+ // flip
+ log.debug("flipping image");
+ BufferedImage result = new BufferedImage(owidth, oheight, img.getType());
+ Graphics2D g = result.createGraphics();
+ g.drawImage(img, owidth, 0, -owidth, oheight, null);
+ g.dispose();
+ img = result;
}
- log.debug("EXIF orientation " + orientation + ", rotating " + rotation + "rad");
- BufferedImage result = new BufferedImage(width, height, img.getType());
- Graphics2D g = result.createGraphics();
- g.translate((width - owidth) / 2, (height - oheight) / 2);
- g.rotate(rotation, owidth / 2, oheight / 2);
- g.drawRenderedImage(img, null);
- g.dispose();
- img = result;
- owidth = width;
- oheight = height;
- }
- if (((orientation < 5) && (orientation % 2 == 0)) ||
- (orientation > 5) && (orientation % 2 == 1)) {
- // flip
- log.debug("flipping image");
- BufferedImage result = new BufferedImage(owidth, oheight, img.getType());
- Graphics2D g = result.createGraphics();
- g.drawImage(img, owidth, 0, -owidth, oheight, null);
- g.dispose();
- img = result;
}
} catch (ImageProcessingException e) {
log.error("Error reading emblem metadata", e);
} catch (MetadataException e) {
log.error("Error reading emblem metadata", e);
+ } catch (NullPointerException e) {
+ log.error("Error reading emblem metadata", e);
}
}
}