Search code examples
javaexificafe

how to fill windows exif tags


Good evening I want to fill in the jpg photo file windows properties

Apparently these are the exiftags

[Exif IFD0] Windows XP Title
[Exif IFD0] Windows XP Author
[Exif IFD0] Windows XP Subject

I looked at the side of icafe.jar but have not found these tags. Can I make it with icafe or other jar library ?

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import com.icafe4j.image.meta.Metadata;
import com.icafe4j.image.meta.exif.Exif;
import com.icafe4j.image.meta.jpeg.JpegExif;
import com.icafe4j.image.meta.exif.ExifTag;
import com.icafe4j.image.tiff.TiffTag;
import com.icafe4j.image.tiff.FieldType;

fin = new FileInputStream(Fm_filePathIn);
fout = new FileOutputStream(Fm_filePathOut);


List<Metadata> metaList = new ArrayList<Metadata>();
 metaList.add(populateExif(JpegExif.class));

Exif populateExif(Class<?> exifClass) throws IOException {

Exif exif = new JpegExif();

    exif.addImageField(ExifTag.WINDOWS_XP_AUTHOR, FieldType.WINDOWSXP, "Toto");
    exif.addImageField(ExifTag.WINDOWS_XP_KEYWORDS, FieldType.WINDOWSXP, "Copyright;Authorbisou");
// Insert ThumbNailIFD
    // Since we don't provide thumbnail image, it will be created later from the input stream
    exif.setThumbnailRequired(true);

    return exif;
  }


        fin.close();
        fout.close();

Solution

  • Those tags do exist in ICAFE but they are not Exiftag. They are TiffTag. Replace the ExifTag with TiffTag, it will work. Look at the TestMetada.java, it clearly shows that.

    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;
    
    import com.icafe4j.image.meta.Metadata;
    import com.icafe4j.image.meta.exif.Exif;
    import com.icafe4j.image.meta.jpeg.JpegExif;
    import com.icafe4j.image.meta.exif.ExifTag;
    import com.icafe4j.image.tiff.TiffTag;
    import com.icafe4j.image.tiff.FieldType;
    
    public class TestWindowsXP {
    
     public static void main(String[] args) throws IOException {
    
        FileInputStream fin = new FileInputStream(Fm_filePathIn);
        FileOutputStream fout = new FileOutputStream(Fm_filePathOut);
    
        List<Metadata> metaList = new ArrayList<Metadata>();
    
        Exif exif = new JpegExif();
    
        exif.addImageField(TiffTag.WINDOWS_XP_AUTHOR, FieldType.WINDOWSXP, "Toto");
        exif.addImageField(TiffTag.WINDOWS_XP_KEYWORDS, FieldType.WINDOWSXP, "Copyright;Authorbisou");
        // Insert ThumbNailIFD
        // Since we don't provide thumbnail image, it will be created later from the input stream
        exif.setThumbnailRequired(true);
    
        metaList.add(exif);
        Metadata.insertMetadata(metaList, fin, fout);
    
        fin.close();
        fout.close();
     }
    }
    

    And the following is a screenshot when I right-click the resulting image->show properties. You can see the information you wanted to insert is showing.

    enter image description here