Example usage for org.apache.commons.imaging.formats.tiff.constants TiffTagConstants TIFF_TAG_MODEL

List of usage examples for org.apache.commons.imaging.formats.tiff.constants TiffTagConstants TIFF_TAG_MODEL

Introduction

In this page you can find the example usage for org.apache.commons.imaging.formats.tiff.constants TiffTagConstants TIFF_TAG_MODEL.

Prototype

TagInfoAscii TIFF_TAG_MODEL

To view the source code for org.apache.commons.imaging.formats.tiff.constants TiffTagConstants TIFF_TAG_MODEL.

Click Source Link

Usage

From source file:at.ac.tuwien.qse.sepm.service.impl.ExifServiceImpl.java

@Override
public Exif getExif(Photo photo) throws ServiceException {
    File file = new File(photo.getPath());
    String exposure = "not available";
    double aperture = 0.0;
    double focalLength = 0.0;
    int iso = 0;/*from  w  ww .j  ava2s  .  co m*/
    boolean flash = false;
    String make = "not available";
    String model = "not available";
    double altitude = 0.0;

    try {
        final ImageMetadata metadata = Imaging.getMetadata(file);
        final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;

        if (jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_EXPOSURE_TIME) != null) {
            exposure = jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_EXPOSURE_TIME)
                    .getValueDescription().split(" ")[0];
        }

        if (jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_APERTURE_VALUE) != null) {
            aperture = jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_APERTURE_VALUE)
                    .getDoubleValue();
        }
        if (jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_FOCAL_LENGTH) != null) {
            focalLength = jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_FOCAL_LENGTH)
                    .getDoubleValue();
        }
        if (jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_ISO) != null) {
            iso = jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_ISO).getIntValue();
        }

        if (jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_FLASH) != null) {
            flash = jpegMetadata.findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_FLASH)
                    .getIntValue() != 0;
        }

        if (jpegMetadata.findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_MAKE) != null) {
            make = jpegMetadata.findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_MAKE)
                    .getValueDescription();
        }
        if (jpegMetadata.findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_MODEL) != null) {
            model = jpegMetadata.findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_MODEL)
                    .getValueDescription();
        }

        if (jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_ALTITUDE) != null) {
            altitude = jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_ALTITUDE)
                    .getDoubleValue();
        }

        return new Exif(photo.getId(), exposure, aperture, focalLength, iso, flash, make, model, altitude);
    } catch (IOException | ImageReadException e) {
        throw new ServiceException(e.getMessage(), e);
    }
}

From source file:net.mozq.picto.core.ProcessCore.java

public static void findFiles(ProcessCondition processCondition, Consumer<ProcessData> processDataSetter,
        BooleanSupplier processStopper) throws IOException {

    Set<FileVisitOption> fileVisitOptionSet;
    if (processCondition.isFollowLinks()) {
        fileVisitOptionSet = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
    } else {/*from  w w w  . j a  v a2  s.  com*/
        fileVisitOptionSet = Collections.emptySet();
    }

    Files.walkFileTree(processCondition.getSrcRootPath(), fileVisitOptionSet, processCondition.getDept(),
            new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
                        throws IOException {
                    if (processStopper.getAsBoolean()) {
                        return FileVisitResult.TERMINATE;
                    }

                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {

                    if (attrs.isDirectory()) {
                        return FileVisitResult.SKIP_SUBTREE;
                    }

                    if (processStopper.getAsBoolean()) {
                        return FileVisitResult.TERMINATE;
                    }

                    if (!processCondition.getPathFilter().accept(file, attrs)) {
                        return FileVisitResult.SKIP_SUBTREE;
                    }

                    Path rootRelativeSubPath = processCondition.getSrcRootPath().relativize(file.getParent());

                    ImageMetadata imageMetadata = getImageMetadata(file);

                    Date baseDate;
                    if (processCondition.isChangeFileCreationDate()
                            || processCondition.isChangeFileModifiedDate()
                            || processCondition.isChangeFileAccessDate()
                            || processCondition.isChangeExifDate()) {
                        baseDate = getBaseDate(processCondition, file, attrs, imageMetadata);
                    } else {
                        baseDate = null;
                    }

                    String destSubPathname = processCondition.getDestSubPathFormat().format(varName -> {
                        try {
                            switch (varName) {
                            case "Now":
                                return new Date();
                            case "ParentSubPath":
                                return rootRelativeSubPath.toString();
                            case "FileName":
                                return file.getFileName().toString();
                            case "BaseName":
                                return FileUtilz.getBaseName(file.getFileName().toString());
                            case "Extension":
                                return FileUtilz.getExt(file.getFileName().toString());
                            case "Size":
                                return Long.valueOf(Files.size(file));
                            case "CreationDate":
                                return (processCondition.isChangeFileCreationDate()) ? baseDate
                                        : new Date(attrs.creationTime().toMillis());
                            case "ModifiedDate":
                                return (processCondition.isChangeFileModifiedDate()) ? baseDate
                                        : new Date(attrs.lastModifiedTime().toMillis());
                            case "AccessDate":
                                return (processCondition.isChangeFileAccessDate()) ? baseDate
                                        : new Date(attrs.lastAccessTime().toMillis());
                            case "PhotoTakenDate":
                                return (processCondition.isChangeExifDate()) ? baseDate
                                        : getPhotoTakenDate(file, imageMetadata);
                            case "Width":
                                return getEXIFIntValue(imageMetadata,
                                        ExifTagConstants.EXIF_TAG_EXIF_IMAGE_WIDTH);
                            case "Height":
                                return getEXIFIntValue(imageMetadata,
                                        ExifTagConstants.EXIF_TAG_EXIF_IMAGE_LENGTH);
                            case "FNumber":
                                return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_FNUMBER);
                            case "Aperture":
                                return getEXIFDoubleValue(imageMetadata,
                                        ExifTagConstants.EXIF_TAG_APERTURE_VALUE);
                            case "MaxAperture":
                                return getEXIFDoubleValue(imageMetadata,
                                        ExifTagConstants.EXIF_TAG_MAX_APERTURE_VALUE);
                            case "ISO":
                                return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_ISO);
                            case "FocalLength":
                                return getEXIFDoubleValue(imageMetadata,
                                        ExifTagConstants.EXIF_TAG_FOCAL_LENGTH); // ?
                            case "FocalLength35mm":
                                return getEXIFDoubleValue(imageMetadata,
                                        ExifTagConstants.EXIF_TAG_FOCAL_LENGTH_IN_35MM_FORMAT);
                            case "ShutterSpeed":
                                return getEXIFDoubleValue(imageMetadata,
                                        ExifTagConstants.EXIF_TAG_SHUTTER_SPEED_VALUE);
                            case "Exposure":
                                return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE); // 
                            case "ExposureTime":
                                return getEXIFDoubleValue(imageMetadata,
                                        ExifTagConstants.EXIF_TAG_EXPOSURE_TIME); // 
                            case "ExposureMode":
                                return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE_MODE);
                            case "ExposureProgram":
                                return getEXIFIntValue(imageMetadata,
                                        ExifTagConstants.EXIF_TAG_EXPOSURE_PROGRAM);
                            case "Brightness":
                                return getEXIFDoubleValue(imageMetadata,
                                        ExifTagConstants.EXIF_TAG_BRIGHTNESS_VALUE);
                            case "WhiteBalance":
                                return getEXIFIntValue(imageMetadata,
                                        ExifTagConstants.EXIF_TAG_WHITE_BALANCE_1);
                            case "LightSource":
                                return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_LIGHT_SOURCE);
                            case "Lens":
                                return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS);
                            case "LensMake":
                                return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS_MAKE);
                            case "LensModel":
                                return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS_MODEL);
                            case "LensSerialNumber":
                                return getEXIFStringValue(imageMetadata,
                                        ExifTagConstants.EXIF_TAG_LENS_SERIAL_NUMBER);
                            case "Make":
                                return getEXIFStringValue(imageMetadata, TiffTagConstants.TIFF_TAG_MAKE);
                            case "Model":
                                return getEXIFStringValue(imageMetadata, TiffTagConstants.TIFF_TAG_MODEL);
                            case "SerialNumber":
                                return getEXIFStringValue(imageMetadata,
                                        ExifTagConstants.EXIF_TAG_SERIAL_NUMBER);
                            case "Software":
                                return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_SOFTWARE);
                            case "ProcessingSoftware":
                                return getEXIFStringValue(imageMetadata,
                                        ExifTagConstants.EXIF_TAG_PROCESSING_SOFTWARE);
                            case "OwnerName":
                                return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_OWNER_NAME);
                            case "CameraOwnerName":
                                return getEXIFStringValue(imageMetadata,
                                        ExifTagConstants.EXIF_TAG_CAMERA_OWNER_NAME);
                            case "GPSLat":
                                return getEXIFGpsLat(imageMetadata);
                            case "GPSLatDeg":
                                return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE,
                                        0);
                            case "GPSLatMin":
                                return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE,
                                        1);
                            case "GPSLatSec":
                                return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE,
                                        2);
                            case "GPSLatRef":
                                return getEXIFStringValue(imageMetadata,
                                        GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);
                            case "GPSLon":
                                return getEXIFGpsLon(imageMetadata);
                            case "GPSLonDeg":
                                return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE,
                                        0);
                            case "GPSLonMin":
                                return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE,
                                        1);
                            case "GPSLonSec":
                                return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE,
                                        2);
                            case "GPSLonRef":
                                return getEXIFStringValue(imageMetadata,
                                        GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);
                            case "GPSAlt":
                                return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_ALTITUDE);
                            case "GPSAltRef":
                                return getEXIFIntValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_ALTITUDE_REF);
                            default:
                                throw new PictoInvalidDestinationPathException(Messages
                                        .getString("message.warn.invalid.destSubPath.varName", varName));
                            }
                        } catch (PictoException e) {
                            throw e;
                        } catch (Exception e) {
                            throw new PictoInvalidDestinationPathException(
                                    Messages.getString("message.warn.invalid.destSubPath.pattern"), e);
                        }
                    });

                    Path destSubPath = processCondition.getDestRootPath().resolve(destSubPathname).normalize();

                    if (!destSubPath.startsWith(processCondition.getDestRootPath())) {
                        throw new PictoInvalidDestinationPathException(
                                Messages.getString("message.warn.invalid.destination.path", destSubPath));
                    }

                    ProcessData processData = new ProcessData();
                    processData.setSrcPath(file);
                    processData.setSrcFileAttributes(attrs);
                    processData.setDestPath(destSubPath);
                    processData.setBaseDate(baseDate);

                    processDataSetter.accept(processData);

                    return FileVisitResult.CONTINUE;
                }
            });
}

From source file:net.tourbook.photo.Photo.java

/**
 * Creates metadata from image metadata/*from w w  w.  j ava 2  s.  c  o  m*/
 * 
 * @param imageMetadata
 *            Can be <code>null</code> when not available
 * @return
 */
private PhotoImageMetadata createPhotoMetadata(final IImageMetadata imageMetadata) {

    final PhotoImageMetadata photoMetadata = new PhotoImageMetadata();

    /*
     * read meta data for this photo
     */
    if (imageMetadata instanceof TiffImageMetadata) {

        photoMetadata.isExifFromImage = true;

        final TiffImageMetadata tiffMetadata = (TiffImageMetadata) imageMetadata;

        photoMetadata.exifDateTime = getTiffValueDate(tiffMetadata);

        photoMetadata.orientation = 1;

        photoMetadata.imageWidth = getTiffValueInt(tiffMetadata, TiffTagConstants.TIFF_TAG_IMAGE_WIDTH,
                Integer.MIN_VALUE);

        photoMetadata.imageHeight = getTiffValueInt(tiffMetadata, TiffTagConstants.TIFF_TAG_IMAGE_LENGTH,
                Integer.MIN_VALUE);

        photoMetadata.model = getTiffValueString(tiffMetadata, TiffTagConstants.TIFF_TAG_MODEL);

    } else if (imageMetadata instanceof JpegImageMetadata) {

        photoMetadata.isExifFromImage = true;

        final JpegImageMetadata jpegMetadata = (JpegImageMetadata) imageMetadata;

        photoMetadata.exifDateTime = getExifValueDate(jpegMetadata);

        photoMetadata.orientation = getExifValueInt(jpegMetadata, TiffTagConstants.TIFF_TAG_ORIENTATION, 1);

        photoMetadata.imageWidth = getExifValueInt(jpegMetadata, ExifTagConstants.EXIF_TAG_EXIF_IMAGE_WIDTH,
                Integer.MIN_VALUE);

        photoMetadata.imageHeight = getExifValueInt(jpegMetadata, ExifTagConstants.EXIF_TAG_EXIF_IMAGE_LENGTH,
                Integer.MIN_VALUE);

        photoMetadata.imageDirection = getExifValueDouble(jpegMetadata,
                GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);

        photoMetadata.altitude = getExifValueDouble(jpegMetadata, GpsTagConstants.GPS_TAG_GPS_ALTITUDE);

        photoMetadata.model = getExifValueString(jpegMetadata, TiffTagConstants.TIFF_TAG_MODEL);

        /*
         * GPS
         */
        final TiffImageMetadata exifMetadata = jpegMetadata.getExif();
        if (exifMetadata != null) {

            try {
                final TiffImageMetadata.GPSInfo gpsInfo = exifMetadata.getGPS();
                if (gpsInfo != null) {

                    photoMetadata.latitude = gpsInfo.getLatitudeAsDegreesNorth();
                    photoMetadata.longitude = gpsInfo.getLongitudeAsDegreesEast();
                }
            } catch (final Exception e) {
                // ignore
            }
        }
        photoMetadata.gpsAreaInfo = getExifValueGpsArea(jpegMetadata);

        /*
         * photoshop metadata
         */
        final JpegPhotoshopMetadata pshopMetadata = jpegMetadata.getPhotoshop();
        if (pshopMetadata != null) {

            final List<? extends IImageMetadataItem> pshopItems = pshopMetadata.getItems();

            for (final IImageMetadataItem pshopItem : pshopItems) {

                if (pshopItem instanceof Item) {

                    final Item item = (Item) pshopItem;
                    final String keyword = item.getKeyword();

                    if (keyword.equals(IptcTypes.OBJECT_NAME.name)) {

                        photoMetadata.objectName = item.getText();

                    } else if (keyword.equals(IptcTypes.CAPTION_ABSTRACT.name)) {
                        photoMetadata.captionAbstract = item.getText();
                    }
                }
            }

        }
    }

    // set file date time
    photoMetadata.fileDateTime = _imageFileLastModified;

    //// this will log all available meta data
    //      System.out.println(UI.timeStampNano());
    //      System.out.println(UI.timeStampNano() + " " + imageFileName);
    //      System.out.println(UI.timeStampNano());
    //      System.out.println(imageMetadata.toString());
    //      System.out.println(UI.timeStampNano());
    //      System.out.println(photoMetadata);
    //      System.out.println(UI.timeStampNano());
    //      // TODO remove SYSTEM.OUT.PRINTLN

    return photoMetadata;
}

From source file:zz.filecollector.fileprocessor.JpgPhotoProcessor.java

@Override
public void extractFileInfo(File file, FileInfo info) {
    FileProcessor.getBasicFileInfo(file, info);
    if (info.getFileType() == FileInfo.UNKNOWN) {
        info.setFileType(FileInfo.PHOTO);
    }//from   w  w  w  .  j  a  v  a  2  s.  com

    try {
        ImageMetadata metadata = Imaging.getMetadata(file);
        if (metadata instanceof JpegImageMetadata) {
            final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;

            if (info.getCreateDate() == null) {
                try {
                    TiffField dateTime = jpegMetadata
                            .findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_DATE_TIME);
                    if (dateTime != null) {
                        String str = dateTime.getStringValue(); // 2014:02:06 12:11:26
                        if (StringUtils.isNotEmpty(str)) {
                            Date date = dateFormat.parse(str);
                            info.setCreateDate(date);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            if (info.getDevice() == null) {
                TiffField model = jpegMetadata.findEXIFValueWithExactMatch(TiffTagConstants.TIFF_TAG_MODEL);
                if (model != null) {
                    byte[] bytes = model.getByteArrayValue();
                    String modelStr = new String(bytes).trim();
                    if (StringUtils.isNotEmpty(modelStr)) {
                        info.setDevice(modelStr);
                    }
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}