List of usage examples for org.apache.commons.imaging.formats.jpeg.iptc PhotoshopApp13Data PhotoshopApp13Data
public PhotoshopApp13Data(final List<IptcRecord> records, final List<IptcBlock> rawBlocks)
From source file:joachimeichborn.geotag.io.jpeg.PictureMetadataWriter.java
private void setGeocoding(final Path aTargetFile) throws IOException, ImageReadException, ImageWriteException { final Path sourceFile = picture.getFile(); final PhotoshopApp13Data photoshopMetadata = getPhotoshopMetadata(sourceFile); if (photoshopMetadata == null) { throw new ImageReadException("Could not obtain photoshop metadata"); }/*from w w w . j a v a 2 s . c o m*/ try (final OutputStream os = new BufferedOutputStream(new FileOutputStream(aTargetFile.toFile()))) { final Geocoding geocoding = picture.getGeocoding(); final EnumSet<IptcTypes> filterTypes = EnumSet.noneOf(IptcTypes.class); filterTypes.add(IptcTypes.CONTENT_LOCATION_NAME); filterTypes.add(IptcTypes.CITY); filterTypes.add(IptcTypes.SUBLOCATION); filterTypes.add(IptcTypes.PROVINCE_STATE); filterTypes.add(IptcTypes.COUNTRY_PRIMARY_LOCATION_CODE); filterTypes.add(IptcTypes.COUNTRY_PRIMARY_LOCATION_NAME); final List<IptcRecord> records = photoshopMetadata.getRecords(); final Iterator<IptcRecord> iter = records.iterator(); while (iter.hasNext()) { final IptcRecord record = iter.next(); final IptcType type = record.iptcType; if (filterTypes.contains(type)) { iter.remove(); } } records.add(new IptcRecord(IptcTypes.CONTENT_LOCATION_NAME, geocoding != null ? geocoding.getLocationName() : "")); records.add(new IptcRecord(IptcTypes.CITY, geocoding != null ? geocoding.getCity() : "")); records.add(new IptcRecord(IptcTypes.SUBLOCATION, geocoding != null ? geocoding.getSublocation() : "")); records.add(new IptcRecord(IptcTypes.PROVINCE_STATE, geocoding != null ? geocoding.getProvinceState() : "")); records.add(new IptcRecord(IptcTypes.COUNTRY_PRIMARY_LOCATION_CODE, geocoding != null ? geocoding.getCountryCode() : "")); records.add(new IptcRecord(IptcTypes.COUNTRY_PRIMARY_LOCATION_NAME, geocoding != null ? geocoding.getCountryName() : "")); final List<IptcBlock> rawBlocks = photoshopMetadata.getRawBlocks(); new JpegIptcRewriter().writeIPTC(sourceFile.toFile(), os, new PhotoshopApp13Data(records, rawBlocks)); } }