Mercurial > hg > digilib-old
diff servlet/src/digilib/image/ImageInfoDocuImage.java @ 564:4c51d71aef13 digilibPDF
more reshuffling of classes
author | robcast |
---|---|
date | Fri, 17 Dec 2010 22:03:14 +0100 |
parents | |
children | 50f291d808b1 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/servlet/src/digilib/image/ImageInfoDocuImage.java Fri Dec 17 22:03:14 2010 +0100 @@ -0,0 +1,51 @@ +/** + * + */ +package digilib.image; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; + +import org.marcoschmidt.image.ImageInfo; + +import digilib.io.ImageFile; + +/** Simple abstract implementation of the <code>DocuImage</code> interface. + * Implements only the identify method using the ImageInfo class. + * @author casties + * + */ +public abstract class ImageInfoDocuImage extends DocuImageImpl { + + /** Check image size and type and store in ImageFile f */ + public ImageFile identify(ImageFile imgf) throws IOException { + // fileset to store the information + File f = imgf.getFile(); + if (f == null) { + throw new IOException("File not found!"); + } + RandomAccessFile raf = new RandomAccessFile(f, "r"); + // set up ImageInfo object + ImageInfo iif = new ImageInfo(); + iif.setInput(raf); + iif.setCollectComments(false); + iif.setDetermineImageNumber(false); + logger.debug("identifying (ImageInfo) " + f); + // try with ImageInfo first + if (iif.check()) { + ImageSize d = new ImageSize(iif.getWidth(), iif.getHeight()); + imgf.setSize(d); + imgf.setMimetype(iif.getMimeType()); + //logger.debug(" format:"+iif.getFormatName()); + raf.close(); + logger.debug("image size: " + imgf.getSize()); + return imgf; + } else { + raf.close(); + } + return null; + } + + +}