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);