Examples of JpegPhotoshopMetadata


Examples of org.apache.sanselan.formats.jpeg.JpegPhotoshopMetadata

            boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
            params
                    .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
                            !ignoreImageData));

            JpegPhotoshopMetadata metadata = new JpegImageParser()
                    .getPhotoshopMetadata(byteSource, params);
            assertNotNull(metadata);
            // metadata.dump();

            File noIptcFile = createTempFile(imageFile.getName()
                    + ".iptc.remove.", ".jpg");
            {
                // test remove

                OutputStream os = null;
                try
                {
                    os = new FileOutputStream(noIptcFile);
                    os = new BufferedOutputStream(os);
                    new JpegIptcRewriter().removeIPTC(byteSource, os);
                } finally
                {
                    if (os != null) {
                        os.close();
                    }
                    os = null;
                }

                JpegPhotoshopMetadata outMetadata = new JpegImageParser()
                        .getPhotoshopMetadata(new ByteSourceFile(noIptcFile),
                                params);
                assertTrue(outMetadata == null
                        || outMetadata.getItems().size() == 0);
            }

        }
    }
View Full Code Here

Examples of org.apache.sanselan.formats.jpeg.JpegPhotoshopMetadata

                    .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
                            !ignoreImageData));
            // params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
            // params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);

            JpegPhotoshopMetadata metadata = new JpegImageParser()
                    .getPhotoshopMetadata(byteSource, params);
            assertNotNull(metadata);
            metadata.dump();

            File noIptcFile = createTempFile(imageFile.getName()
                    + ".iptc.remove.", ".jpg");
            {
                // test remove

                OutputStream os = null;
                try
                {
                    os = new FileOutputStream(noIptcFile);
                    os = new BufferedOutputStream(os);
                    new JpegIptcRewriter().removeIPTC(byteSource, os);
                } finally
                {
                    if (os != null) {
                        os.close();
                    }
                    os = null;
                }

                // Debug.debug("Source Segments:");
                // new JpegUtils().dumpJFIF(new ByteSourceFile(noIptcFile));

                JpegPhotoshopMetadata outMetadata = new JpegImageParser()
                        .getPhotoshopMetadata(new ByteSourceFile(noIptcFile),
                                params);
                assertTrue(outMetadata == null
                        || outMetadata.getItems().size() == 0);
            }
            {
                // test no-change update

                List newBlocks = metadata.photoshopApp13Data.getNonIptcBlocks();
                List oldRecords = metadata.photoshopApp13Data.getRecords();
                List newRecords = new ArrayList();
                for (int j = 0; j < oldRecords.size(); j++)
                {
                    IPTCRecord record = (IPTCRecord) oldRecords.get(j);
                    if (record.iptcType.type != IPTCConstants.IPTC_TYPE_CITY.type
                            && record.iptcType.type != IPTCConstants.IPTC_TYPE_CREDIT.type)
                        newRecords.add(record);
                }

                newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
                        "Albany, NY"));
                newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
                        "William Sorensen"));

                PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
                        newBlocks);

                File updated = createTempFile(imageFile.getName()
                        + ".iptc.update.", ".jpg");
                OutputStream os = null;
                try
                {
                    os = new FileOutputStream(updated);
                    os = new BufferedOutputStream(os);
                    new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
                } finally
                {
                    if (os != null) {
                        os.close();
                    }
                    os = null;
                }

                // Debug.debug("Source Segments:");
                // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));

                ByteSource updateByteSource = new ByteSourceFile(updated);
                JpegPhotoshopMetadata outMetadata = new JpegImageParser()
                        .getPhotoshopMetadata(updateByteSource, params);

                // Debug.debug("outMetadata", outMetadata.toString());
                // Debug.debug("hasIptcSegment", new JpegImageParser()
                // .hasIptcSegment(updateByteSource));

                assertNotNull(outMetadata);
                assertTrue(outMetadata.getItems().size() == newRecords.size());
                // assertEquals(metadata.toString(), outMetadata.toString());
            }

            {
                // test update

                List newBlocks = metadata.photoshopApp13Data.getNonIptcBlocks();
                List newRecords = new ArrayList();

                newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
                        "Albany, NY"));
                newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
                        "William Sorensen"));

                PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
                        newBlocks);

                File updated = createTempFile(imageFile.getName()
                        + ".iptc.update.", ".jpg");
                OutputStream os = null;
                try
                {
                    os = new FileOutputStream(updated);
                    os = new BufferedOutputStream(os);
                    new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
                } finally
                {
                    if (os != null) {
                        os.close();
                    }
                    os = null;
                }

                // Debug.debug("Source Segments:");
                // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));

                ByteSource updateByteSource = new ByteSourceFile(updated);
                JpegPhotoshopMetadata outMetadata = new JpegImageParser()
                        .getPhotoshopMetadata(updateByteSource, params);

                // Debug.debug("outMetadata", outMetadata.toString());
                // Debug.debug("hasIptcSegment", new JpegImageParser()
                // .hasIptcSegment(updateByteSource));

                assertNotNull(outMetadata);
                assertTrue(outMetadata.getItems().size() == 2);
                // assertEquals(metadata.toString(), outMetadata.toString());
            }

            {
                // test insert

                List newBlocks = new ArrayList();
                List newRecords = new ArrayList();

                newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
                        "Albany, NY"));
                newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
                        "William Sorensen"));

                PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
                        newBlocks);

                File updated = createTempFile(imageFile.getName()
                        + ".iptc.insert.", ".jpg");
                OutputStream os = null;
                try
                {
                    os = new FileOutputStream(updated);
                    os = new BufferedOutputStream(os);
                    new JpegIptcRewriter().writeIPTC(new ByteSourceFile(
                            noIptcFile), os, newData);
                } finally
                {
                    if (os != null) {
                        os.close();
                    }
                    os = null;
                }

                // Debug.debug("Source Segments:");
                // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));

                ByteSource updateByteSource = new ByteSourceFile(updated);
                JpegPhotoshopMetadata outMetadata = new JpegImageParser()
                        .getPhotoshopMetadata(updateByteSource, params);

                // Debug.debug("outMetadata", outMetadata.toString());
                // Debug.debug("hasIptcSegment", new JpegImageParser()
                // .hasIptcSegment(updateByteSource));

                assertNotNull(outMetadata);
                assertTrue(outMetadata.getItems().size() == 2);
                // assertEquals(metadata.toString(), outMetadata.toString());
            }

        }
    }
View Full Code Here

Examples of org.apache.sanselan.formats.jpeg.JpegPhotoshopMetadata

            boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
            params
                    .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
                            !ignoreImageData));

            JpegPhotoshopMetadata metadata = new JpegImageParser()
                    .getPhotoshopMetadata(byteSource, params);
            // metadata.dump();

            {
                List newBlocks = new ArrayList();
                List newRecords = new ArrayList();

                if (null != metadata)
                {
                    boolean keepOldIptcNonTextValues = true;
                    if (keepOldIptcNonTextValues)
                        newBlocks.addAll(metadata.photoshopApp13Data
                                .getNonIptcBlocks());
                    boolean keepOldIptcTextValues = true;
                    if (keepOldIptcTextValues)
                    {
                        List oldRecords = metadata.photoshopApp13Data
                                .getRecords();

                        newRecords = new ArrayList();
                        for (int j = 0; j < oldRecords.size(); j++)
                        {
                            IPTCRecord record = (IPTCRecord) oldRecords.get(j);
                            if (record.iptcType.type != IPTCConstants.IPTC_TYPE_CITY.type
                                    && record.iptcType.type != IPTCConstants.IPTC_TYPE_CREDIT.type)
                                newRecords.add(record);
                        }
                    }
                }

                newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
                        "Albany, NY"));
                newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
                        "William Sorensen"));

                PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
                        newBlocks);

                File updated = createTempFile(imageFile.getName()
                        + ".iptc.add.", ".jpg");
                OutputStream os = null;
                try
                {
                    os = new FileOutputStream(updated);
                    os = new BufferedOutputStream(os);
                    new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
                } finally
                {
                    if (os != null) {
                        os.close();
                    }
                    os = null;
                }

                // Debug.debug("Destination Segments:");
                // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));

                ByteSource updateByteSource = new ByteSourceFile(updated);
                JpegPhotoshopMetadata outMetadata = new JpegImageParser()
                        .getPhotoshopMetadata(updateByteSource, params);

                // Debug.debug("outMetadata", outMetadata.toString());
                // Debug.debug("hasIptcSegment", new JpegImageParser()
                // .hasIptcSegment(updateByteSource));

                assertNotNull(outMetadata);
                assertTrue(outMetadata.getItems().size() == newRecords.size());
                // assertEquals(metadata.toString(), outMetadata.toString());
            }

        }
    }
View Full Code Here

Examples of org.apache.sanselan.formats.jpeg.JpegPhotoshopMetadata

            metadata.getPhotoshop().dump();
            // if(metadata.getPhotoshop().getItems().size()>0)
            // Debug.debug("iptc size",
            // metadata.getPhotoshop().getItems().size());

            JpegPhotoshopMetadata psMetadata = metadata.getPhotoshop();
            List oldRecords = psMetadata.photoshopApp13Data.getRecords();

            System.out.println();
            for (int j = 0; j < oldRecords.size(); j++)
            {
View Full Code Here

Examples of org.apache.sanselan.formats.jpeg.JpegPhotoshopMetadata

      metadata.getPhotoshop().dump();
      // if(metadata.getPhotoshop().getItems().size()>0)
      // Debug.debug("iptc size",
      // metadata.getPhotoshop().getItems().size());

      JpegPhotoshopMetadata psMetadata = metadata.getPhotoshop();
      List oldRecords = psMetadata.photoshopApp13Data.getRecords();

      System.out.println();
      for (int j = 0; j < oldRecords.size(); j++)
      {
View Full Code Here

Examples of org.apache.sanselan.formats.jpeg.JpegPhotoshopMetadata

      boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
      params
          .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
              !ignoreImageData));

      JpegPhotoshopMetadata metadata = new JpegImageParser()
          .getPhotoshopMetadata(byteSource, params);
      assertNotNull(metadata);
      // metadata.dump();

      File noIptcFile = createTempFile(imageFile.getName()
          + ".iptc.remove.", ".jpg");
      {
        // test remove

        OutputStream os = null;
        try
        {
          os = new FileOutputStream(noIptcFile);
          os = new BufferedOutputStream(os);
          new JpegIptcRewriter().removeIPTC(byteSource, os);
        } finally
        {
          os.close();
          os = null;
        }

        JpegPhotoshopMetadata outMetadata = new JpegImageParser()
            .getPhotoshopMetadata(new ByteSourceFile(noIptcFile),
                params);
        assertTrue(outMetadata == null
            || outMetadata.getItems().size() == 0);
      }

    }
  }
View Full Code Here

Examples of org.apache.sanselan.formats.jpeg.JpegPhotoshopMetadata

          .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
              !ignoreImageData));
      // params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
      // params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);

      JpegPhotoshopMetadata metadata = new JpegImageParser()
          .getPhotoshopMetadata(byteSource, params);
      assertNotNull(metadata);
      metadata.dump();

      File noIptcFile = createTempFile(imageFile.getName()
          + ".iptc.remove.", ".jpg");
      {
        // test remove

        OutputStream os = null;
        try
        {
          os = new FileOutputStream(noIptcFile);
          os = new BufferedOutputStream(os);
          new JpegIptcRewriter().removeIPTC(byteSource, os);
        } finally
        {
          os.close();
          os = null;
        }

        // Debug.debug("Source Segments:");
        // new JpegUtils().dumpJFIF(new ByteSourceFile(noIptcFile));

        JpegPhotoshopMetadata outMetadata = new JpegImageParser()
            .getPhotoshopMetadata(new ByteSourceFile(noIptcFile),
                params);
        assertTrue(outMetadata == null
            || outMetadata.getItems().size() == 0);
      }
      {
        // test no-change update

        List newBlocks = metadata.photoshopApp13Data.getNonIptcBlocks();
        List oldRecords = metadata.photoshopApp13Data.getRecords();
        List newRecords = new ArrayList();
        for (int j = 0; j < oldRecords.size(); j++)
        {
          IPTCRecord record = (IPTCRecord) oldRecords.get(j);
          if (record.iptcType.type != IPTCConstants.IPTC_TYPE_CITY.type
              && record.iptcType.type != IPTCConstants.IPTC_TYPE_CREDIT.type)
            newRecords.add(record);
        }

        newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
            "Albany, NY"));
        newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
            "William Sorensen"));

        PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
            newBlocks);

        File updated = createTempFile(imageFile.getName()
            + ".iptc.update.", ".jpg");
        OutputStream os = null;
        try
        {
          os = new FileOutputStream(updated);
          os = new BufferedOutputStream(os);
          new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
        } finally
        {
          os.close();
          os = null;
        }

        // Debug.debug("Source Segments:");
        // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));

        ByteSource updateByteSource = new ByteSourceFile(updated);
        JpegPhotoshopMetadata outMetadata = new JpegImageParser()
            .getPhotoshopMetadata(updateByteSource, params);

        // Debug.debug("outMetadata", outMetadata.toString());
        // Debug.debug("hasIptcSegment", new JpegImageParser()
        // .hasIptcSegment(updateByteSource));

        assertNotNull(outMetadata);
        assertTrue(outMetadata.getItems().size() == newRecords.size());
        // assertEquals(metadata.toString(), outMetadata.toString());
      }

      {
        // test update

        List newBlocks = metadata.photoshopApp13Data.getNonIptcBlocks();
        List newRecords = new ArrayList();

        newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
            "Albany, NY"));
        newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
            "William Sorensen"));

        PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
            newBlocks);

        File updated = createTempFile(imageFile.getName()
            + ".iptc.update.", ".jpg");
        OutputStream os = null;
        try
        {
          os = new FileOutputStream(updated);
          os = new BufferedOutputStream(os);
          new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
        } finally
        {
          os.close();
          os = null;
        }

        // Debug.debug("Source Segments:");
        // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));

        ByteSource updateByteSource = new ByteSourceFile(updated);
        JpegPhotoshopMetadata outMetadata = new JpegImageParser()
            .getPhotoshopMetadata(updateByteSource, params);

        // Debug.debug("outMetadata", outMetadata.toString());
        // Debug.debug("hasIptcSegment", new JpegImageParser()
        // .hasIptcSegment(updateByteSource));

        assertNotNull(outMetadata);
        assertTrue(outMetadata.getItems().size() == 2);
        // assertEquals(metadata.toString(), outMetadata.toString());
      }

      {
        // test insert

        List newBlocks = new ArrayList();
        List newRecords = new ArrayList();

        newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
            "Albany, NY"));
        newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
            "William Sorensen"));

        PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
            newBlocks);

        File updated = createTempFile(imageFile.getName()
            + ".iptc.insert.", ".jpg");
        OutputStream os = null;
        try
        {
          os = new FileOutputStream(updated);
          os = new BufferedOutputStream(os);
          new JpegIptcRewriter().writeIPTC(new ByteSourceFile(
              noIptcFile), os, newData);
        } finally
        {
          os.close();
          os = null;
        }

        // Debug.debug("Source Segments:");
        // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));

        ByteSource updateByteSource = new ByteSourceFile(updated);
        JpegPhotoshopMetadata outMetadata = new JpegImageParser()
            .getPhotoshopMetadata(updateByteSource, params);

        // Debug.debug("outMetadata", outMetadata.toString());
        // Debug.debug("hasIptcSegment", new JpegImageParser()
        // .hasIptcSegment(updateByteSource));

        assertNotNull(outMetadata);
        assertTrue(outMetadata.getItems().size() == 2);
        // assertEquals(metadata.toString(), outMetadata.toString());
      }

    }
  }
View Full Code Here

Examples of org.apache.sanselan.formats.jpeg.JpegPhotoshopMetadata

      boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
      params
          .put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
              !ignoreImageData));

      JpegPhotoshopMetadata metadata = new JpegImageParser()
          .getPhotoshopMetadata(byteSource, params);
      // metadata.dump();

      {
        List newBlocks = new ArrayList();
        List newRecords = new ArrayList();

        if (null != metadata)
        {
          boolean keepOldIptcNonTextValues = true;
          if (keepOldIptcNonTextValues)
            newBlocks.addAll(metadata.photoshopApp13Data
                .getNonIptcBlocks());
          boolean keepOldIptcTextValues = true;
          if (keepOldIptcTextValues)
          {
            List oldRecords = metadata.photoshopApp13Data
                .getRecords();

            newRecords = new ArrayList();
            for (int j = 0; j < oldRecords.size(); j++)
            {
              IPTCRecord record = (IPTCRecord) oldRecords.get(j);
              if (record.iptcType.type != IPTCConstants.IPTC_TYPE_CITY.type
                  && record.iptcType.type != IPTCConstants.IPTC_TYPE_CREDIT.type)
                newRecords.add(record);
            }
          }
        }

        newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
            "Albany, NY"));
        newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
            "William Sorensen"));

        PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
            newBlocks);

        File updated = createTempFile(imageFile.getName()
            + ".iptc.add.", ".jpg");
        OutputStream os = null;
        try
        {
          os = new FileOutputStream(updated);
          os = new BufferedOutputStream(os);
          new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
        } finally
        {
          os.close();
          os = null;
        }

        // Debug.debug("Destination Segments:");
        // new JpegUtils().dumpJFIF(new ByteSourceFile(updated));

        ByteSource updateByteSource = new ByteSourceFile(updated);
        JpegPhotoshopMetadata outMetadata = new JpegImageParser()
            .getPhotoshopMetadata(updateByteSource, params);

        // Debug.debug("outMetadata", outMetadata.toString());
        // Debug.debug("hasIptcSegment", new JpegImageParser()
        // .hasIptcSegment(updateByteSource));

        assertNotNull(outMetadata);
        assertTrue(outMetadata.getItems().size() == newRecords.size());
        // assertEquals(metadata.toString(), outMetadata.toString());
      }

    }
  }
View Full Code Here

Examples of org.apache.sanselan.formats.jpeg.JpegPhotoshopMetadata

    if (removeExif && !removeIptc) {
        // eRewriter.removeExifMetadata(imageByte, bOutputStream); // cheap and dirty

        HashMap<String, Boolean> params = new HashMap<>();
        params.put(SanselanConstants.PARAM_KEY_READ_THUMBNAILS, false);
        JpegPhotoshopMetadata pMetaData = new JpegImageParser().getPhotoshopMetadata(new ByteSourceFile(f),
          params);
        List<IPTCRecord> iptcRecords;
        List<?> nonIptcBlocks = null;
        if (pMetaData != null) {// pick existing IPTC Data
      nonIptcBlocks = pMetaData.photoshopApp13Data.getNonIptcBlocks();
      iptcRecords = pMetaData.photoshopApp13Data.getRecords();
        } else {
      iptcRecords = new ArrayList<IPTCRecord>();
      nonIptcBlocks = new ArrayList<>();
        }
        List<IPTCRecord> newRecords = new ArrayList<>();

        for (IPTCRecord record : iptcRecords) {
      if (record.iptcType.type == IPTCConstants.IPTC_TYPE_ORIGINATING_PROGRAM.type) {
          newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_ORIGINATING_PROGRAM,
            "Dexifier by Andreas Reichart <andreas.reichart@gmail.com>"));
      } else {
          newRecords.add(record);
      }
        }

        PhotoshopApp13Data pApp13Data = new PhotoshopApp13Data(newRecords, nonIptcBlocks);
        iRewriter.writeIPTC(imageByte, bOutputStream, pApp13Data);

    }

    if (!removeExif && removeIptc) {
        HashMap<String, Boolean> params = new HashMap<>();
        params.put(SanselanConstants.PARAM_KEY_READ_THUMBNAILS, false);
        JpegPhotoshopMetadata pMetaData = new JpegImageParser().getPhotoshopMetadata(new ByteSourceFile(f),
          params);
        assert (pMetaData != null);
        // List<?> emptyRecords = pMetaData.photoshopApp13Data.getRawBlocks();

        List<IPTCRecord> emptyRecords = new ArrayList<IPTCRecord>();
        List<IPTCRecord> newRecords = new ArrayList<IPTCRecord>();
        // List<IPTCRecord> emptyRecords = new ArrayList<IPTCRecord>();
        newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_SPECIAL_INSTRUCTIONS,
          "Converted by DeExifier"));
        // generate an empty App13 DataBlock
        PhotoshopApp13Data newMetaData = new PhotoshopApp13Data(newRecords, emptyRecords);
        // iRewriter.removeIPTC(resizedImageByte, bOutputStream);
        // eRewriter.updateExifMetadataLossless(imageByte, bOutputStream,
        // jmd.getExif().getOutputSet());
        iRewriter.writeIPTC(imageByte, bOutputStream, newMetaData);
        // TODO: should be an eRewriter to get back the Exif part!

        IImageMetadata metaData = Sanselan.getMetadata(f);
        JpegImageMetadata jMetaData = (JpegImageMetadata) metaData;
        assert (jMetaData != null);
        TiffImageMetadata exif = jMetaData.getExif();
        TiffOutputSet outputSet = exif.getOutputSet();
        TiffOutputField field = outputSet.findField(TiffConstants.EXIF_TAG_PROCESSING_SOFTWARE);
        if (null != field) {
      outputSet.removeField(TiffConstants.EXIF_TAG_PROCESSING_SOFTWARE);
      String fieldString = "Edited by DeExifier. andreas.reichart@gmail.com";
      TiffOutputField newField = new TiffOutputField(ExifTagConstants.EXIF_TAG_PROCESSING_SOFTWARE,
        TiffFieldTypeConstants.FIELD_TYPE_ASCII, fieldString.length(), fieldString.getBytes());
      TiffOutputDirectory outDirectory = outputSet.getOrCreateExifDirectory();
      outDirectory.add(newField);
        }

        eRewriter.updateExifMetadataLossless(imageByte, bOutputStream, outputSet);

    }

    // if (removeExif & removeIptc) {
    // TODO: removeExif & removeIptc
    // }

    // OK, works: recompressed image is already empty.
    if (!removeExif && !removeIptc) {

        IImageMetadata metadata = Sanselan.getMetadata(f);
        JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
        if (jpegMetadata != null) {
      TiffImageMetadata exif = jpegMetadata.getExif();
      if (exif != null) {
          TiffOutputSet outputSet = exif.getOutputSet();
          TiffOutputSet emptySet = new TiffOutputSet();
          new ExifRewriter().removeExifMetadata(imageByte, bOutputStream);
      }
        }
    }
      }

      // Okiedokie: de-Exify without recompression or resizing
      else {

    if (removeExif && !removeIptc) {
        // only removing Exif data
        // if no recompression should be done, we use the standard Sanselan ExifRewriter
        eRewriter.removeExifMetadata(f, bOutputStream);

    } else if (!removeExif && removeIptc) {
        // only removing the IPTC Data
        // iRewriter.removeIPTC(f, bOutputStream); // simple version
        Map<String, Boolean> params = new HashMap<>();
        params.put(SanselanConstants.PARAM_KEY_READ_THUMBNAILS, false);
        JpegPhotoshopMetadata jpMetadata = new JpegImageParser().getPhotoshopMetadata(
          new ByteSourceFile(f), params);
        List<?> nonIPTCBlocks = jpMetadata.photoshopApp13Data.getNonIptcBlocks();
        List<IPTCRecord> newRecords = new ArrayList<>();
        PhotoshopApp13Data pApp13Data = new PhotoshopApp13Data(newRecords, nonIPTCBlocks);
        iRewriter.writeIPTC(f, bOutputStream, pApp13Data);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.