Search in sources :

Example 1 with ImageInfo

use of org.devlib.schmidt.imageinfo.ImageInfo in project digilib by robcast.

the class ImageInfoDocuImage method identify.

/* Check image size and type and store in ImageFile f */
public ImageInput identify(ImageInput ii) throws IOException {
    logger.debug("identifying (ImageInfo) " + ii);
    RandomAccessFile raf = null;
    try {
        // set up ImageInfo object
        ImageInfo iif = new ImageInfo();
        if (ii.hasImageInputStream()) {
            iif.setInput(ii.getImageInputStream());
        } else if (ii.hasFile()) {
            raf = new RandomAccessFile(ii.getFile(), "r");
            iif.setInput(raf);
        } else {
            return null;
        }
        iif.setCollectComments(false);
        iif.setDetermineImageNumber(false);
        // try with ImageInfo first
        if (iif.check()) {
            ImageSize d = new ImageSize(iif.getWidth(), iif.getHeight());
            ii.setSize(d);
            String mt = iif.getMimeType();
            // fix image/pjpeg
            if (mt.equals("image/pjpeg")) {
                mt = "image/jpeg";
            }
            ii.setMimetype(mt);
            logger.debug("image size: " + ii.getSize());
            return ii;
        }
    } catch (Exception e) {
        logger.debug("ImageInfoDocuimage unable to identify.", e);
    } finally {
        // close file, don't close stream(?)
        if (raf != null) {
            raf.close();
        }
    }
    return null;
}
Also used : RandomAccessFile(java.io.RandomAccessFile) ImageSize(digilib.util.ImageSize) ImageInfo(org.devlib.schmidt.imageinfo.ImageInfo) IOException(java.io.IOException)

Aggregations

ImageSize (digilib.util.ImageSize)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 ImageInfo (org.devlib.schmidt.imageinfo.ImageInfo)1