2
votes

I am using Apache Commons but it is not enough for me because it is so old technology. So ,i found iCafe and it seems better but I am having the error below. Any idea what i am doing wrong?

      private static List<IPTCDataSet> createIPTCDataSet() {
          List<IPTCDataSet> iptcs = new ArrayList<IPTCDataSet>();
          iptcs.add(new IPTCDataSet(IPTCApplicationTag.COPYRIGHT_NOTICE, "Copyright 2014-2016, [email protected]"));
          iptcs.add(new IPTCDataSet(IPTCApplicationTag.CATEGORY, "ICAFE"));
          iptcs.add(new IPTCDataSet(IPTCApplicationTag.KEY_WORDS, "Welcome 'icafe' user!"));

          return iptcs;
      }

      private static IPTC createIPTC() {
        IPTC iptc = new IPTC();
        iptc.addDataSets(createIPTCDataSet());
        return iptc;
      }

      public static void main(String[] args) throws  IOException {

        FileInputStream fin = new FileInputStream("C:/Users/rajab/Desktop/test/ibo.jpeg");
        FileOutputStream fout = new FileOutputStream("C:/Users/rajab/Desktop/test/ibo/ibo.jpeg");

        List<Metadata> metaList = new ArrayList<Metadata>();
        //metaList.add(populateExif(TiffExif.class));
        metaList.add(createIPTC());
        metaList.add(new Comments(Arrays.asList("Comment1", "Comment2")));

        Metadata.insertMetadata(metaList, fin, fout);
    }
}

and my EXCEPTION

run: Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at com.icafe4j.image.meta.Metadata.(Unknown Source) at vectorcleaner.Metadata1.populateExif(Metadata1.java:41) at vectorcleaner.Metadata1.main(Metadata1.java:127) Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 3 more C:\Users\rajab\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 0 seconds)

1
NoClassDefFoundError: org/slf4j/LoggerFactory, so you haven't put SLF4J (or a dependent) into the CLASSPATH. And there is NOTHING to do with the JPA API in that question ...user3973283
I answered your question asked under a closed issue in icafe. Billy Frost is correct. Besides the logging jar, you also need to add all the jar files in the lib folder except the two icafe related jars to you classpath.dragon66
thanks all. ) dragon66 yes you answerd. :)Ibrahim Rajabli
yes. you are right. bu i can't find example about icafe. and have to write code apache common imaging. now i can not finish my code. a little bit difficult for me. my task edit JPG file IPTC keywords and Title.Ibrahim Rajabli
See my answer below. If you have other issues, let me know.dragon66

1 Answers

1
votes

Not sure what exactly you want but here is what ICAFE can do with IPTC metadata:

  • Read IPTC from image.
  • Insert IPTC into image or update IPTC of existing image.
  • Delete IPTC from image.

For reading IPTC, here is an example:

    import java.io.IOException;
    import java.util.List;
    import java.util.Map;
    import java.util.Iterator;

    import com.icafe4j.image.meta.Metadata;
    import com.icafe4j.image.meta.MetadataEntry;
    import com.icafe4j.image.meta.MetadataType;
    import com.icafe4j.image.meta.iptc.IPTC;

    public class ExtractIPTC {

        public static void main(String[] args) throws IOException {
            Map<MetadataType, Metadata> metadataMap = Metadata.readMetadata(args[0]);
            IPTC iptc = (IPTC)metadataMap.get(MetadataType.IPTC);

            if(iptc != null) {
                Iterator<MetadataEntry> iterator = iptc.iterator();

                while(iterator.hasNext()) {
                    MetadataEntry item = iterator.next();
                    printMetadata(item, "", "     ");
                }
            }   
        }
        private void printMetadata(MetadataEntry entry, String indent, String increment) {
            logger.info(indent + entry.getKey() (StringUtils.isNullOrEmpty(entry.getValue())? "" : ": " + entry.getValue()));
            if(entry.isMetadataEntryGroup()) {
                 indent += increment;
                 Collection<MetadataEntry> entries = entry.getMetadataEntries();
                 for(MetadataEntry e : entries) {
                    printMetadata(e, indent, increment);
                 }          
            }
        }   
    }

For insert/update IPTC, here is an example:

    import java.io.IOException;
    import java.util.List;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;

    import com.icafe4j.image.meta.Metadata;
    import com.icafe4j.image.meta.MetadataEntry;
    import com.icafe4j.image.meta.MetadataType;
    import com.icafe4j.image.meta.iptc.IPTCDataSet;
    import com.icafe4j.image.meta.iptc.IPTCApplicationTag;

    public class InsertIPTC {

        public static void main(String[] args) throws IOException {
           FileInputStream fin = new FileInputStream("C:/Users/rajab/Desktop/test/ibo.jpeg");
           FileOutputStream fout = new FileOutputStream("C:/Users/rajab/Desktop/test/ibo/ibo.jpeg");

           Metadata.insertIPTC(fin, fout, createIPTCDataSet(), true);
        }
        private static List<IPTCDataSet> createIPTCDataSet() {
            List<IPTCDataSet> iptcs = new ArrayList<IPTCDataSet>();
            iptcs.add(new IPTCDataSet(IPTCApplicationTag.COPYRIGHT_NOTICE, "Copyright 2014-2016, [email protected]"));
            iptcs.add(new IPTCDataSet(IPTCApplicationTag.OBJECT_NAME, "ICAFE"));
            iptcs.add(new IPTCDataSet(IPTCApplicationTag.KEY_WORDS, "Welcome 'icafe' user!"));

            return iptcs;
        }
    }

The above example uses Metadata.insertIPTC instead of Metadata.insertMetadata because we need one more boolean parameter. If set to true, it will keep the existing IPTC data and only update the those we want. Some of the IPTC entries allow multiple values. In that case, we only append/add the new ones. For other unique entries, they will be replaced by the new ones.

Looks like you want to add key words and title. In your question, you already showed code to insert key words and in order to insert title, use OBJECT_NAME which can be found in the example above.

Note: you can add multiple key words as well. Some softwares can only handle one key words record. In that case, you can put all the key words in one record separated by semi-colon instead of insert multiple entries.