Package com.drew.metadata

Examples of com.drew.metadata.Directory


  }
 
  protected static void showEXIF(File jpegFile) throws Exception{

    Metadata metadata = JpegMetadataReader.readMetadata(jpegFile);
    Directory exif = metadata.getDirectory(ExifDirectory.class);
    int orie = exif.getInt(ExifDirectory.TAG_ORIENTATION);
    if(orie!=1)
      System.out.println(jpegFile.getName()+":"+orie);
   
      Iterator tags = exif.getTagIterator();
      while (tags.hasNext()) {
          Tag tag = (Tag)tags.next();
          // use Tag.toString()
          System.out.println(tag);
      }
View Full Code Here


    //Reading EXIF
    try {
      Metadata metadata = JpegMetadataReader.readMetadata(new File(img_path));
      if(!metadata.containsDirectory(ExifDirectory.class))
        return false;
      Directory exif = metadata.getDirectory(ExifDirectory.class);
      if(exif!=null){
        if(exif.containsTag(ExifDirectory.TAG_ORIENTATION))
          photo.setOrientation(exif.getInt(ExifDirectory.TAG_ORIENTATION));
        if(exif.containsTag(ExifDirectory.TAG_MAKE))
          photo.setManufacturer(exif.getString(ExifDirectory.TAG_MAKE));
        if(exif.containsTag(ExifDirectory.TAG_MODEL))
          photo.setModel(exif.getString(ExifDirectory.TAG_MODEL));
        if(exif.containsTag(ExifDirectory.TAG_APERTURE))
          photo.setAperture(exif.getDescription(ExifDirectory.TAG_APERTURE));
        if(exif.containsTag(ExifDirectory.TAG_COLOR_SPACE))
          photo.setColorSpace(exif.getDescription(ExifDirectory.TAG_COLOR_SPACE));
        if(exif.containsTag(ExifDirectory.TAG_EXPOSURE_BIAS))
          photo.setExposureBias(exif.getDescription(ExifDirectory.TAG_EXPOSURE_BIAS));
        if(exif.containsTag(ExifDirectory.TAG_FOCAL_LENGTH))
          photo.setFocalLength(exif.getDescription(ExifDirectory.TAG_FOCAL_LENGTH));
        if(exif.containsTag(ExifDirectory.TAG_ISO_EQUIVALENT))
          photo.setISO(exif.getInt(ExifDirectory.TAG_ISO_EQUIVALENT));
        if(exif.containsTag(ExifDirectory.TAG_SHUTTER_SPEED))
          photo.setShutter(exif.getDescription(ExifDirectory.TAG_SHUTTER_SPEED))
        if(exif.containsTag(ExifDirectory.TAG_EXPOSURE_TIME))
          photo.setExposureTime(exif.getDescription(ExifDirectory.TAG_EXPOSURE_TIME));
        return true;
      }
    } catch (Exception e) {
      log.error("Reading EXIF of "+img_path+" failed.", e);
    }
View Full Code Here

            File jpegFile = new File(filename);
           
            try {
                Metadata metadata = JpegMetadataReader.readMetadata(jpegFile);
                if (metadata.containsDirectory(ExifDirectory.class)) {
                    Directory exifDirectory = metadata.getDirectory(ExifDirectory.class);
                   
                    try {
                        String camera = exifDirectory.getString(ExifDirectory.TAG_MODEL);
                        image.setValue(Image._Q_CAMERA, camera);
                    } catch (Exception me) {}

                    try {
                        int compression = exifDirectory.getInt(ExifDirectory.TAG_COMPRESSION);
                        image.setValue(Image._O_COMPRESSION, Long.valueOf(compression));
                    } catch (Exception me) {}


                    try {
                        String description = exifDirectory.getString(ExifDirectory.TAG_IMAGE_DESCRIPTION);
                        image.setValue(Image._B_DESCRIPTION, description);
                    } catch (Exception me) {}

                    try {
                        Date date = exifDirectory.getDate(ExifDirectory.TAG_DATETIME);
                        if (date != null) {
                            cal.setTime(date);
                            cal.set(Calendar.HOUR_OF_DAY, 0);
                            cal.set(Calendar.MINUTE, 0);
                            cal.set(Calendar.SECOND, 0);
                            image.setValue(Image._N_DATE, cal.getTime());
                        }
                    } catch (Exception me) {}
                }
               
                if (metadata.containsDirectory(IptcDirectory.class)) {
                    try {
                        Directory iptcDirectory = metadata.getDirectory(IptcDirectory.class);
                        String city = iptcDirectory.getString(IptcDirectory.TAG_CITY);
                        String country = iptcDirectory.getString(IptcDirectory.TAG_COUNTRY_OR_PRIMARY_LOCATION);
                        String state = iptcDirectory.getString(IptcDirectory.TAG_PROVINCE_OR_STATE);
                       
                        String location = "";
                        location += country != null ? country + ", " : "";
                        location += state != null ? state  + ", " : "";
                        location += city != null ? city : "";
View Full Code Here

               
                @SuppressWarnings("unchecked")
                Iterator<Directory> directories = metadata.getDirectoryIterator();
                HashMap<String, String> props = new HashMap<String, String>();
                while (directories.hasNext()) {
                    Directory directory = directories.next();
                    @SuppressWarnings("unchecked")
                    Iterator<Tag> tags = directory.getTagIterator();
                    while (tags.hasNext()) {
                        Tag tag = tags.next();
                        try {
                            props.put(tag.getTagName(), tag.getDescription());
                            ii.info.append(tag.getTagName() + ": " + tag.getDescription() + " .\n");
View Full Code Here

            com.drew.metadata.Metadata jpegMetadata =
                JpegMetadataReader.readMetadata(stream);

            Iterator<?> directories = jpegMetadata.getDirectoryIterator();
            while (directories.hasNext()) {
                Directory directory = (Directory) directories.next();
                Iterator<?> tags = directory.getTagIterator();

                while (tags.hasNext()) {
                    Tag tag = (Tag)tags.next();
                    metadata.set(tag.getTagName(), tag.getDescription());
                }
View Full Code Here

    public void testHandleDirectories() throws MetadataException {
        Metadata metadata = mock(Metadata.class);
        ImageMetadataExtractor.DirectoryHandler handler1 = mock(ImageMetadataExtractor.DirectoryHandler.class);
        ImageMetadataExtractor e = new ImageMetadataExtractor(metadata, handler1);
       
        Directory directory = new JpegCommentDirectory();
        Iterator directories = mock(Iterator.class);
        when(directories.hasNext()).thenReturn(true, false);
        when(directories.next()).thenReturn(directory);
        when(handler1.supports(JpegCommentDirectory.class)).thenReturn(true);
       
View Full Code Here

                metadata.get(TikaCoreProperties.CREATED));
    }
   
    @Test
    public void testCopyUnknownFieldsHandler() throws MetadataException {
        Directory d = mock(Directory.class);
        Tag t1 = mock(Tag.class);
        when(t1.getTagName()).thenReturn("Image Description");
        when(t1.getDescription()).thenReturn("t1");
        Tag t2 = mock(Tag.class);
        when(t2.getTagName()).thenReturn(Metadata.KEYWORDS);
        when(t2.getDescription()).thenReturn("known");
        Tag t3 = mock(Tag.class);
        when(t3.getTagName()).thenReturn(TikaCoreProperties.DESCRIPTION.getName());
        when(t3.getDescription()).thenReturn("known");
        List<Tag> tags = Arrays.asList(t1, t2, t3);
        when(d.getTags()).thenReturn(tags);
        Metadata metadata = new Metadata();
        new ImageMetadataExtractor.CopyUnknownFieldsHandler().handle(d, metadata);
        assertEquals("t1", metadata.get("Image Description"));
        assertNull("keywords should be excluded from bulk copy because it is a defined field",
                metadata.get(Metadata.KEYWORDS));
View Full Code Here

  private String getPrintableExifInfo(ImageActionVO vo){
    try {
      StringBuffer appendInfo = new StringBuffer();
        //get image meta object
      Metadata metadata = JpegMetadataReader.readMetadata(vo.getInputImageFile());
      Directory exifDic = metadata.getDirectory(ExifDirectory.class);
      //camera module
      if(vo.getParams().isAppendCamera()){
        String info = getExifInfo(exifDic,ExifDirectory.TAG_MODEL);
        if(!StringUtil.isNullOrBlank(info)){
          appendInfo.append(StringUtil.getPrintString(info));
View Full Code Here

        InputStream in = null;
        try {
            in = fileHandler.getInputStream();
            Metadata metadata = JpegMetadataReader.readMetadata(in);
            in.close();
            Directory exifIFD0Directory = metadata.getDirectory(ExifIFD0Directory.class);
            Directory exifSubIFDDirectory = metadata.getDirectory(ExifSubIFDDirectory.class);
            Directory jpgDirectory = metadata.getDirectory(JpegDirectory.class);
            if (exifIFD0Directory != null) {
                setupCameraModel(image, exifIFD0Directory);
            }
            if (exifSubIFDDirectory != null) {
                setupCreatedDate(image, exifSubIFDDirectory);
View Full Code Here

                    result = wptFromGpsTag(gps);
                }
            }
            if (!hasGpsDirectory) {
                System.err.println("Warning no dedicated GPS directory found. Looking for GPS info in main Exif directory.");
                Directory dir = meta.getDirectory(ExifDirectory.class);
                if(dir.hasErrors()){
                    System.err.println("Warning: Exif directory has errors.");
                    java.util.Iterator it = dir.getErrors();
                    while(it.hasNext()){
                        System.out.println(it.next());
                    }
                }
                result = wptFromGpsTag(dir);
View Full Code Here

TOP

Related Classes of com.drew.metadata.Directory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.