Add TIF decoder update metadata parser
That's Twelvemonkeys for TIF Drewnoakes for metadata
This commit is contained in:
parent
d98455658b
commit
cb2a20ed2c
4 changed files with 51 additions and 27 deletions
19
pom.xml
19
pom.xml
|
|
@ -119,7 +119,7 @@
|
|||
<dependency>
|
||||
<groupId>com.drewnoakes</groupId>
|
||||
<artifactId>metadata-extractor</artifactId>
|
||||
<version>2.6.2</version>
|
||||
<version>2.18.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
|
|
@ -220,6 +220,23 @@
|
|||
<artifactId>tika-core</artifactId>
|
||||
<version>2.9.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio-jpeg</artifactId>
|
||||
<version>3.9.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.imageio</groupId>
|
||||
<artifactId>imageio-tiff</artifactId>
|
||||
<version>3.9.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.twelvemonkeys.servlet</groupId>
|
||||
<artifactId>servlet</artifactId>
|
||||
<version>3.9.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ import javax.imageio.ImageReadParam;
|
|||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
|
||||
import com.drew.imaging.ImageMetadataReader;
|
||||
import com.drew.imaging.ImageProcessingException;
|
||||
import com.drew.imaging.jpeg.JpegProcessingException;
|
||||
import org.forkalsrud.album.db.DirectoryProps;
|
||||
import org.forkalsrud.album.video.MovieCoder;
|
||||
|
|
@ -83,7 +85,7 @@ public class DirectoryMetadataGenerator {
|
|||
// cache.properties and album.properties
|
||||
continue;
|
||||
}
|
||||
if (name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".JPG")) {
|
||||
if (name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".JPG") || name.endsWith(".tif") || name.endsWith(".tiff") || name.endsWith(".TIF")) {
|
||||
Map<String, String> p = generateThumbnailProperties(f);
|
||||
if (p != null) {
|
||||
addPropsForFile(props, f, p);
|
||||
|
|
@ -132,22 +134,27 @@ public class DirectoryMetadataGenerator {
|
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
|
||||
NumberFormat nf = new DecimalFormat("0");
|
||||
|
||||
|
||||
Metadata metadata;
|
||||
try {
|
||||
metadata = JpegMetadataReader.readMetadata(f);
|
||||
} catch (JpegProcessingException e) {
|
||||
metadata = ImageMetadataReader.readMetadata(f);
|
||||
} catch (ImageProcessingException e) {
|
||||
// not a JPEG file
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Directory exifDirectory = metadata.getDirectory(ExifIFD0Directory.class);
|
||||
if (exifDirectory != null && exifDirectory.containsTag(ExifIFD0Directory.TAG_ORIENTATION)) {
|
||||
int orientation = exifDirectory.getInt(ExifIFD0Directory.TAG_ORIENTATION);
|
||||
props.put("orientation", nf.format(orientation));
|
||||
hasOrientation = true;
|
||||
Directory exifDirectory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
|
||||
if (exifDirectory != null
|
||||
&& exifDirectory.containsTag(ExifSubIFDDirectory.TAG_IMAGE_WIDTH)
|
||||
&& exifDirectory.containsTag(ExifSubIFDDirectory.TAG_IMAGE_HEIGHT)) {
|
||||
int width = exifDirectory.getInt(ExifSubIFDDirectory.TAG_IMAGE_WIDTH);
|
||||
int height = exifDirectory.getInt(ExifSubIFDDirectory.TAG_IMAGE_HEIGHT);
|
||||
props.put("dimensions", new Dimension(width, height).toString());
|
||||
hasDim = true;
|
||||
}
|
||||
Directory exifSubDirectory = metadata.getDirectory(ExifSubIFDDirectory.class);
|
||||
if (exifSubDirectory != null && exifSubDirectory.containsTag(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH) &&
|
||||
|
||||
Directory exifSubDirectory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
|
||||
if (exifSubDirectory != null && exifSubDirectory.containsTag(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH) &&
|
||||
exifSubDirectory.containsTag(ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT)) {
|
||||
int width = exifSubDirectory.getInt(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH);
|
||||
int height = exifSubDirectory.getInt(ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT);
|
||||
|
|
@ -165,11 +172,13 @@ public class DirectoryMetadataGenerator {
|
|||
String comment = exifSubDirectory.getString(ExifSubIFDDirectory.TAG_USER_COMMENT);
|
||||
props.put("comment", comment);
|
||||
}
|
||||
Directory jpegDirectory = metadata.getDirectory(JpegDirectory.class);
|
||||
if (jpegDirectory.containsTag(JpegDirectory.TAG_JPEG_IMAGE_WIDTH) &&
|
||||
jpegDirectory.containsTag(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT)) {
|
||||
int width = jpegDirectory.getInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
|
||||
int height = jpegDirectory.getInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
|
||||
|
||||
JpegDirectory jpegDirectory = metadata.getFirstDirectoryOfType(JpegDirectory.class);
|
||||
if (jpegDirectory != null
|
||||
&& jpegDirectory.containsTag(JpegDirectory.TAG_IMAGE_WIDTH)
|
||||
&& jpegDirectory.containsTag(JpegDirectory.TAG_IMAGE_HEIGHT)) {
|
||||
int width = jpegDirectory.getImageWidth();
|
||||
int height = jpegDirectory.getImageHeight();
|
||||
props.put("dimensions", new Dimension(width, height).toString());
|
||||
hasDim = true;
|
||||
}
|
||||
|
|
@ -196,7 +205,7 @@ public class DirectoryMetadataGenerator {
|
|||
|
||||
private Date getExifDate(Directory exifDirectory, int tagName) throws MetadataException {
|
||||
|
||||
String dateStr = (String)exifDirectory.getObject(tagName);
|
||||
String dateStr = exifDirectory.getString(tagName);
|
||||
if (" : : : : ".equals(dateStr)) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -274,7 +274,12 @@ public class AlbumServlet
|
|||
|
||||
if (pathInfo.endsWith(".json")) {
|
||||
pathInfo = pathInfo.substring(0, pathInfo.length() - ".json".length());
|
||||
handleJson(req, res, (DirectoryEntry)resolveEntry(pathInfo));
|
||||
DirectoryEntry directoryEntry = (DirectoryEntry)resolveEntry(pathInfo);
|
||||
if (directoryEntry == null) {
|
||||
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
handleJson(req, res, directoryEntry);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -298,7 +303,6 @@ public class AlbumServlet
|
|||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.fillInStackTrace();
|
||||
throw new ServletException("sadness", e);
|
||||
}
|
||||
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
|
|
|
|||
|
|
@ -170,14 +170,8 @@ public class PictureScaler {
|
|||
while (intermediate.getWidth() < targetWidth) {
|
||||
intermediate = intermediate.doubled();
|
||||
}
|
||||
|
||||
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("jpg");
|
||||
ImageReader reader = readers.next();
|
||||
ImageInputStream iis = ImageIO.createImageInputStream(file);
|
||||
reader.setInput(iis, true);
|
||||
ImageReadParam param = reader.getDefaultReadParam();
|
||||
BufferedImage img = reader.read(0, param);
|
||||
iis.close();
|
||||
|
||||
BufferedImage img = ImageIO.read(file);
|
||||
|
||||
// The orientation is about flipping and rotating. Here is what an 'F' looks like
|
||||
// on pictures with each orientation.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue