title: How to remove Exif,IPTC,XMP data of a png image in Java
body: <p>We are trying to remove Exif,IPTC and XMP data for png image. Please provide sample code for same</p>
  <ol>
  <li>We are having a png image file.</li>
  <li>Need to remove Exif,IPTC and XMP data.</li>
  </ol>
  <blockquote>
  <pre><code>package com.test;
  
  import java.io.BufferedOutputStream;
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.OutputStream;
  
  import org.apache.commons.imaging.ImageReadException;
  import org.apache.commons.imaging.ImageWriteException;
  import org.apache.commons.imaging.formats.jpeg.iptc.JpegIptcRewriter;
  
  class ImageUploadTest {
  
    public static void main(String[] args) {
  
        try {
  
            final File original = new File(
                    &quot;/Users/anupam256093/Downloads/Test.png&quot;);
            final File newimage = new File(
                    &quot;/Users/anupam256093/Downloads/Test_resized2.png&quot;);
            removeExifTag(original, newimage);
  
        } catch (Exception e) {
            System.out.println(e.getMessage());
            System.out.println(e);
        }
  
    }
  
    public static void removeExifTag(final File jpegImageFile, final File dst) {
        OutputStream os = null;
        OutputStream osiptc = null;
  
        try {
            System.out.println(&quot;4&quot;);
  
            os = new FileOutputStream(dst);
            os = new BufferedOutputStream(os);
            System.out.println(&quot;15&quot;);
            osiptc = new FileOutputStream(dst);
            osiptc = new BufferedOutputStream(osiptc);
            new JpegIptcRewriter().removeIPTC(jpegImageFile, os);
            // new ExifRewriter().removeExifMetadata(jpegImageFile, os);
            System.out.println(&quot;15&quot;);
  
            //new PngWriter(true).writeImage(jpegImageFile, os, null);
            //System.out.println(&quot;16&quot;);
  
            os.close();
            os = null;
            System.out.println(&quot;7&quot;);
  
            System.out.println(&quot;SUCCESS&quot;);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            System.out.println(&quot;ERROR&quot;);
            e.printStackTrace();
        } catch (ImageWriteException e) {
            // TODO Auto-generated catch block
            System.out.println(&quot;ERROR1&quot;);
  
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            System.out.println(&quot;ERROR2&quot;);
  
            e.printStackTrace();
        } catch (ImageReadException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (final IOException e) {
  
                }
            }
        }
    }
  
  }
  </code></pre>
  </blockquote>
  <p>We are trying to remove Exif,IPTC and XMP data for png image. Please provide sample code for same</p>
  <ol>
  <li>We are having a png image file.</li>
  <li>Need to remove Exif,IPTC and XMP data.</li>
  </ol>