1 | package fr.mael.jiwigo.transverse.util; |
---|
2 | |
---|
3 | import java.io.File; |
---|
4 | import java.util.HashMap; |
---|
5 | import java.util.Iterator; |
---|
6 | |
---|
7 | import com.drew.imaging.jpeg.JpegMetadataReader; |
---|
8 | import com.drew.imaging.jpeg.JpegProcessingException; |
---|
9 | import com.drew.metadata.Directory; |
---|
10 | import com.drew.metadata.Metadata; |
---|
11 | import com.drew.metadata.MetadataException; |
---|
12 | import com.drew.metadata.Tag; |
---|
13 | |
---|
14 | public class MetadataUtil { |
---|
15 | public static HashMap<Integer, String> getIptcMap() { |
---|
16 | HashMap<Integer, String> tagNameMap = new HashMap<Integer, String>(); |
---|
17 | // tagNameMap.put(new Integer(512), "Directory Version"); |
---|
18 | tagNameMap.put(new Integer(632), "iptc_Caption_Abstract"); |
---|
19 | tagNameMap.put(new Integer(634), "iptc_Writer_Editor"); |
---|
20 | tagNameMap.put(new Integer(617), "iptc_Headline"); |
---|
21 | tagNameMap.put(new Integer(552), "iptc_Special_Instructions"); |
---|
22 | tagNameMap.put(new Integer(592), "iptc_By_line"); |
---|
23 | tagNameMap.put(new Integer(597), "iptc_By_line_Title"); |
---|
24 | tagNameMap.put(new Integer(622), "iptc_Credit"); |
---|
25 | tagNameMap.put(new Integer(627), "iptc_Source"); |
---|
26 | tagNameMap.put(new Integer(517), "iptc_Object"); |
---|
27 | tagNameMap.put(new Integer(567), "iptc_Date_Created"); |
---|
28 | tagNameMap.put(new Integer(602), "iptc_City"); |
---|
29 | tagNameMap.put(new Integer(607), "iptc_Province_State"); |
---|
30 | tagNameMap.put(new Integer(613), "iptc_Country_Primary_Location_Code"); |
---|
31 | tagNameMap.put(new Integer(615), "iptc_Original_Transmission_Reference"); |
---|
32 | tagNameMap.put(new Integer(527), "iptc_Category"); |
---|
33 | tagNameMap.put(new Integer(532), "iptc_Supplemental_Category"); |
---|
34 | tagNameMap.put(new Integer(522), "iptc_Urgency"); |
---|
35 | tagNameMap.put(new Integer(537), "iptc_Keywords"); |
---|
36 | tagNameMap.put(new Integer(628), "iptc_Copyright_Notice"); |
---|
37 | tagNameMap.put(new Integer(542), "iptc_Release_Date"); |
---|
38 | tagNameMap.put(new Integer(547), "iptc_Release_Time"); |
---|
39 | tagNameMap.put(new Integer(572), "iptc_Time_Created"); |
---|
40 | tagNameMap.put(new Integer(577), "iptc_Originating_Program"); |
---|
41 | return tagNameMap; |
---|
42 | } |
---|
43 | |
---|
44 | public static HashMap<Integer, String> getExifMap() { |
---|
45 | HashMap<Integer, String> tagNameMap = new HashMap<Integer, String>(); |
---|
46 | tagNameMap.put(new Integer(266), "exif_field_FillOrder"); |
---|
47 | tagNameMap.put(new Integer(269), "exif_field_DocumentName"); |
---|
48 | tagNameMap.put(new Integer(4096), "exif_field_RelatedImageFileFormat"); |
---|
49 | tagNameMap.put(new Integer(4097), "exif_field_RelatedImageWidth"); |
---|
50 | tagNameMap.put(new Integer(4098), "exif_field_RelatedImageLength"); |
---|
51 | tagNameMap.put(new Integer(342), "exif_field_TransferRange"); |
---|
52 | tagNameMap.put(new Integer(512), "exif_field_JPEGProc"); |
---|
53 | tagNameMap.put(new Integer(34665), "exif_field_ExifOffset"); |
---|
54 | tagNameMap.put(new Integer(37122), "exif_field_CompressedBitsPerPixel"); |
---|
55 | // tagNameMap.put(new Integer(37500), "Maker Note"); |
---|
56 | tagNameMap.put(new Integer(40965), "exif_field_InteropOffset"); |
---|
57 | // tagNameMap.put(new Integer(254), "New Subfile Type"); |
---|
58 | tagNameMap.put(new Integer(255), "exif_field_SubfileType"); |
---|
59 | // tagNameMap.put(new Integer(256), "Thumbnail Image Width"); |
---|
60 | // tagNameMap.put(new Integer(257), "Thumbnail Image Height"); |
---|
61 | tagNameMap.put(new Integer(258), "exif_field_BitsPerSample"); |
---|
62 | tagNameMap.put(new Integer(259), "exif_field_Compression"); |
---|
63 | tagNameMap.put(new Integer(262), "exif_field_PhotometricInterpretation"); |
---|
64 | tagNameMap.put(new Integer(263), "exif_field_Thresholding"); |
---|
65 | tagNameMap.put(new Integer(270), "exif_field_ImageDescription"); |
---|
66 | tagNameMap.put(new Integer(271), "exif_field_Make"); |
---|
67 | tagNameMap.put(new Integer(272), "exif_field_Model"); |
---|
68 | tagNameMap.put(new Integer(273), "exif_field_StripOffsets"); |
---|
69 | tagNameMap.put(new Integer(274), "exif_field_Orientation"); |
---|
70 | tagNameMap.put(new Integer(277), "exif_field_SamplesPerPixel"); |
---|
71 | tagNameMap.put(new Integer(278), "exif_field_RowsPerStrip"); |
---|
72 | tagNameMap.put(new Integer(279), "exif_field_StripByteCounts"); |
---|
73 | tagNameMap.put(new Integer(282), "exif_field_XResolution"); |
---|
74 | tagNameMap.put(new Integer(283), "exif_field_YResolution"); |
---|
75 | tagNameMap.put(new Integer(285), "exif_field_PageName"); |
---|
76 | tagNameMap.put(new Integer(284), "exif_field_PlanarConfiguration"); |
---|
77 | tagNameMap.put(new Integer(296), "exif_field_ResolutionUnit"); |
---|
78 | tagNameMap.put(new Integer(301), "exif_field_TransferFunction"); |
---|
79 | tagNameMap.put(new Integer(305), "exif_field_Software"); |
---|
80 | tagNameMap.put(new Integer(306), "exif_field_TakenDate"); |
---|
81 | tagNameMap.put(new Integer(315), "exif_field_Artist"); |
---|
82 | tagNameMap.put(new Integer(317), "exif_field_Predictor"); |
---|
83 | tagNameMap.put(new Integer(318), "exif_field_WhitePoint"); |
---|
84 | tagNameMap.put(new Integer(319), "exif_field_PrimaryChromaticities"); |
---|
85 | tagNameMap.put(new Integer(322), "exif_field_TileWidth"); |
---|
86 | tagNameMap.put(new Integer(323), "exif_field_TileLength"); |
---|
87 | tagNameMap.put(new Integer(324), "exif_field_TileOffsets"); |
---|
88 | tagNameMap.put(new Integer(325), "exif_field_TileByteCounts"); |
---|
89 | tagNameMap.put(new Integer(330), "exif_field_SubIFD"); |
---|
90 | tagNameMap.put(new Integer(347), "exif_field_JPEGTables"); |
---|
91 | tagNameMap.put(new Integer(513), "exif_field_ThumbnailOffset"); |
---|
92 | tagNameMap.put(new Integer(514), "exif_field_ThumbnailLength"); |
---|
93 | // tagNameMap.put(new Integer(61441), "Thumbnail Data"); |
---|
94 | tagNameMap.put(new Integer(529), "exif_field_YCbCrCoefficients"); |
---|
95 | tagNameMap.put(new Integer(530), "exif_field_YCbCrSubSampling"); |
---|
96 | tagNameMap.put(new Integer(531), "exif_field_YCbCrPositioning"); |
---|
97 | tagNameMap.put(new Integer(532), "exif_field_ReferenceBlackWhite"); |
---|
98 | tagNameMap.put(new Integer(33421), "exif_field_CFARepeatPatternDim"); |
---|
99 | tagNameMap.put(new Integer(33422), "exif_field_CFAPattern2"); |
---|
100 | tagNameMap.put(new Integer(33423), "exif_field_BatteryLevel"); |
---|
101 | tagNameMap.put(new Integer(33432), "exif_field_Copyright"); |
---|
102 | tagNameMap.put(new Integer(33434), "exif_field_ExposureTime"); |
---|
103 | tagNameMap.put(new Integer(33437), "exif_field_FNumber"); |
---|
104 | tagNameMap.put(new Integer(33723), "exif_field_IPTC-NAA"); |
---|
105 | tagNameMap.put(new Integer(34675), "exif_field_ICC_Profile"); |
---|
106 | tagNameMap.put(new Integer(34850), "exif_field_ExposureProgram"); |
---|
107 | tagNameMap.put(new Integer(34852), "exif_field_SpectralSensitivity"); |
---|
108 | tagNameMap.put(new Integer(34853), "exif_field_GPSInfo"); |
---|
109 | tagNameMap.put(new Integer(34855), "exif_field_ISOSpeedRatings"); |
---|
110 | tagNameMap.put(new Integer(34856), "exif_field_Opto-ElectricConvFactor"); |
---|
111 | tagNameMap.put(new Integer(34857), "exif_field_Interlace"); |
---|
112 | tagNameMap.put(new Integer(34858), "exif_field_TimeZoneOffset"); |
---|
113 | tagNameMap.put(new Integer(34859), "exif_field_SelfTimer"); |
---|
114 | tagNameMap.put(new Integer(36864), "exif_field_ExifVersion"); |
---|
115 | tagNameMap.put(new Integer(36867), "exif_field_DateTimeOriginal"); |
---|
116 | // tagNameMap.put(new Integer(36868), "Date/Time Digitized"); |
---|
117 | tagNameMap.put(new Integer(37121), "exif_field_ComponentsConfiguration"); |
---|
118 | tagNameMap.put(new Integer(37377), "exif_field_ShutterSpeedValue"); |
---|
119 | tagNameMap.put(new Integer(37378), "exif_field_ApertureValue"); |
---|
120 | tagNameMap.put(new Integer(37379), "exif_field_BrightnessValue"); |
---|
121 | tagNameMap.put(new Integer(37380), "exif_field_ExposureBiasValue"); |
---|
122 | tagNameMap.put(new Integer(37381), "exif_field_MaxApertureValue"); |
---|
123 | tagNameMap.put(new Integer(37382), "exif_field_SubjectDistance"); |
---|
124 | tagNameMap.put(new Integer(37383), "exif_field_MeteringMode"); |
---|
125 | tagNameMap.put(new Integer(37384), "exif_field_LightSource"); |
---|
126 | tagNameMap.put(new Integer(37385), "exif_field_Flash"); |
---|
127 | tagNameMap.put(new Integer(37386), "exif_field_FocalLength"); |
---|
128 | tagNameMap.put(new Integer(37387), "exif_field_FlashActivity"); |
---|
129 | tagNameMap.put(new Integer(37388), "exif_field_SpatialFrequencyResponse"); |
---|
130 | tagNameMap.put(new Integer(37389), "exif_field_Noise"); |
---|
131 | tagNameMap.put(new Integer(37393), "exif_field_ImageNumber"); |
---|
132 | tagNameMap.put(new Integer(37394), "exif_field_SecurityClassification"); |
---|
133 | tagNameMap.put(new Integer(37395), "exif_field_ImageHistory"); |
---|
134 | tagNameMap.put(new Integer(37396), "exif_field_SubjectLocation"); |
---|
135 | tagNameMap.put(new Integer(41493), "exif_field_ExposureIndex"); |
---|
136 | tagNameMap.put(new Integer(37398), "exif_field_TIFF-EPStandardID"); |
---|
137 | tagNameMap.put(new Integer(37510), "exif_field_UserComment"); |
---|
138 | tagNameMap.put(new Integer(37520), "exif_field_SubSecTime"); |
---|
139 | tagNameMap.put(new Integer(37521), "exif_field_SubSecTimeOriginal"); |
---|
140 | tagNameMap.put(new Integer(37522), "exif_field_SubSecTimeDigitized"); |
---|
141 | tagNameMap.put(new Integer(40960), "exif_field_FlashpixVersion"); |
---|
142 | tagNameMap.put(new Integer(40961), "exif_field_ColorSpace"); |
---|
143 | tagNameMap.put(new Integer(40962), "exif_field_ExifImageWidth"); |
---|
144 | // tagNameMap.put(new Integer(40963), "Exif Image Height"); |
---|
145 | tagNameMap.put(new Integer(40964), "exif_field_RelatedSoundFile"); |
---|
146 | tagNameMap.put(new Integer(41483), "exif_field_FlashEnergy"); |
---|
147 | tagNameMap.put(new Integer(41484), "exif_field_SpatialFrequencyResponse"); |
---|
148 | tagNameMap.put(new Integer(41486), "exif_field_FocalPlaneXResolution"); |
---|
149 | tagNameMap.put(new Integer(41487), "exif_field_FocalPlaneYResolution"); |
---|
150 | tagNameMap.put(new Integer(41488), "exif_field_FocalPlaneResolutionUnit"); |
---|
151 | tagNameMap.put(new Integer(41492), "exif_field_SubjectLocation"); |
---|
152 | tagNameMap.put(new Integer(37397), "exif_field_ExposureIndex"); |
---|
153 | tagNameMap.put(new Integer(41495), "exif_field_SensingMethod"); |
---|
154 | tagNameMap.put(new Integer(41728), "exif_field_FileSource"); |
---|
155 | tagNameMap.put(new Integer(41729), "exif_field_SceneType"); |
---|
156 | tagNameMap.put(new Integer(41730), "exif_field_CFAPattern"); |
---|
157 | tagNameMap.put(new Integer(41985), "exif_field_CustomRendered"); |
---|
158 | tagNameMap.put(new Integer(41986), "exif_field_ExposureMode"); |
---|
159 | tagNameMap.put(new Integer(41987), "exif_field_WhiteBalance"); |
---|
160 | tagNameMap.put(new Integer(41988), "exif_field_DigitalZoomRatio"); |
---|
161 | tagNameMap.put(new Integer(41989), "exif_field_FocalLengthIn35mmFormat"); |
---|
162 | tagNameMap.put(new Integer(41990), "exif_field_SceneCaptureType"); |
---|
163 | tagNameMap.put(new Integer(41991), "exif_field_GainControl"); |
---|
164 | tagNameMap.put(new Integer(41992), "exif_field_Contrast"); |
---|
165 | tagNameMap.put(new Integer(41993), "exif_field_Saturation"); |
---|
166 | tagNameMap.put(new Integer(41994), "exif_field_Sharpness"); |
---|
167 | tagNameMap.put(new Integer(41995), "exif_field_DeviceSettingDescription"); |
---|
168 | tagNameMap.put(new Integer(41996), "exif_field_SubjectDistanceRange"); |
---|
169 | // tagNameMap.put(new Integer(40093), "Windows XP Author"); |
---|
170 | // tagNameMap.put(new Integer(40092), "Windows XP Comment"); |
---|
171 | // tagNameMap.put(new Integer(40094), "Windows XP Keywords"); |
---|
172 | // tagNameMap.put(new Integer(40095), "Windows XP Subject"); |
---|
173 | // tagNameMap.put(new Integer(40091), "Windows XP Title"); |
---|
174 | tagNameMap.put(new Integer(280), "exif_field_MinSampleValue"); |
---|
175 | tagNameMap.put(new Integer(281), "exif_field_MaxSampleValue"); |
---|
176 | return tagNameMap; |
---|
177 | } |
---|
178 | |
---|
179 | public static HashMap<String, String> getTagsHashMap(String fichier) throws JpegProcessingException, |
---|
180 | MetadataException { |
---|
181 | File jpegFile = new File(fichier); |
---|
182 | Metadata metadata = JpegMetadataReader.readMetadata(jpegFile); |
---|
183 | Iterator directories = metadata.getDirectoryIterator(); |
---|
184 | HashMap<String, String> mapTags = new HashMap<String, String>(); |
---|
185 | while (directories.hasNext()) { |
---|
186 | Directory directory = (Directory) directories.next(); |
---|
187 | Iterator tags = directory.getTagIterator(); |
---|
188 | if (directory.getName().equals("Exif") || directory.getName().equals("Iptc")) { |
---|
189 | while (tags.hasNext()) { |
---|
190 | Tag tag = (Tag) tags.next(); |
---|
191 | if (tag.getDirectoryName().equals("Exif")) { |
---|
192 | for (Integer key : MetadataUtil.getExifMap().keySet()) { |
---|
193 | if (tag.getTagType() == key) { |
---|
194 | mapTags.put(MetadataUtil.getExifMap().get(key), tag.getDescription()); |
---|
195 | } |
---|
196 | } |
---|
197 | } else { |
---|
198 | for (Integer key : MetadataUtil.getIptcMap().keySet()) { |
---|
199 | if (tag.getTagType() == key) { |
---|
200 | mapTags.put(MetadataUtil.getIptcMap().get(key), tag.getDescription()); |
---|
201 | } |
---|
202 | } |
---|
203 | } |
---|
204 | } |
---|
205 | } |
---|
206 | } |
---|
207 | return mapTags; |
---|
208 | } |
---|
209 | |
---|
210 | public static void main(String[] args) { |
---|
211 | try { |
---|
212 | HashMap<String, String> map = getTagsHashMap("/home/mael/Images/exif.JPG"); |
---|
213 | for (String key : getTagsHashMap("/home/mael/Images/exif.JPG").keySet()) { |
---|
214 | System.out.println(key + " -> " + map.get(key)); |
---|
215 | } |
---|
216 | } catch (JpegProcessingException e) { |
---|
217 | // TODO Auto-generated catch block |
---|
218 | e.printStackTrace(); |
---|
219 | } catch (MetadataException e) { |
---|
220 | // TODO Auto-generated catch block |
---|
221 | e.printStackTrace(); |
---|
222 | } |
---|
223 | } |
---|
224 | } |
---|