Subversion Repositories eFlore/Applications.cel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
623 aurelien 1
<?php
2460 jpm 2
// declare(encoding='UTF-8');
623 aurelien 3
/**
2460 jpm 4
 * Classe d'extraction de metadonnées d'un fichier JPEG afin de les mettre dans un tableau au format du CEL.
623 aurelien 5
 *
2460 jpm 6
 * @internal   Mininum PHP version : 5.2
7
 * @category   CEL
8
 * @package    Services
9
 * @subpackage Bibliothèques
10
 * @version    0.1
11
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
12
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
13
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
14
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
15
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
16
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
623 aurelien 17
 */
632 aurelien 18
class ExtracteurMetadonnees {
623 aurelien 19
 
1155 jpm 20
	private $meta = array();
21
	private $tableau_ids_tags_exif = array(
22
			'InteropIndex' => '1',
23
			'InteropVersion' => '2',
24
			'ProcessingSoftware' => '11',
25
			'SubfileType' => '254',
26
			'OldSubfileType' => '255',
27
			'ImageWidth' => '256',
28
			'ImageHeight' => '257',
29
			'BitsPerSample' => '258',
30
			'Compression' => '259',
31
			'PhotometricInterpretation' => '262',
32
			'Thresholding' => '263',
33
			'CellWidth' => '264',
34
			'CellLength' => '265',
35
			'FillOrder' => '266',
36
			'DocumentName' => '269',
37
			'ImageDescription' => '270',
38
			'Make' => '271',
39
			'Model' => '272',
40
			'StripOffsets' => '273',
41
			'Orientation' => '274',
42
			'SamplesPerPixel' => '277',
43
			'RowsPerStrip' => '278',
44
			'StripByteCounts' => '279',
45
			'MinSampleValue' => '280',
46
			'MaxSampleValue' => '281',
47
			'XResolution' => '282',
48
			'YResolution' => '283',
49
			'PlanarConfiguration' => '284',
50
			'PageName' => '285',
51
			'XPosition' => '286',
52
			'YPosition' => '287',
53
			'FreeOffsets' => '288',
54
			'FreeByteCounts' => '289',
55
			'GrayResponseUnit' => '290',
56
			'GrayResponseCurve' => '291',
57
			'T4Options' => '292',
58
			'T6Options' => '293',
59
			'ResolutionUnit' => '296',
60
			'PageNumber' => '297',
61
			'ColorResponseUnit' => '300',
62
			'TransferFunction' => '301',
63
			'Software' => '305',
64
			'ModifyDate' => '306',
65
			'Artist' => '315',
66
			'HostComputer' => '316',
67
			'Predictor' => '317',
68
			'WhitePoint' => '318',
69
			'PrimaryChromaticities' => '319',
70
			'ColorMap' => '320',
71
			'HalftoneHints' => '321',
72
			'TileWidth' => '322',
73
			'TileLength' => '323',
74
			'TileOffsets' => '324',
75
			'TileByteCounts' => '325',
76
			'BadFaxLines' => '326',
77
			'CleanFaxData' => '327',
78
			'ConsecutiveBadFaxLines' => '328',
79
			'SubIFD' => '330',
80
			'InkSet' => '332',
81
			'InkNames' => '333',
82
			'NumberofInks' => '334',
83
			'DotRange' => '336',
84
			'TargetPrinter' => '337',
85
			'ExtraSamples' => '338',
86
			'SampleFormat' => '339',
87
			'SMinSampleValue' => '340',
88
			'SMaxSampleValue' => '341',
89
			'TransferRange' => '342',
90
			'ClipPath' => '343',
91
			'XClipPathUnits' => '344',
92
			'YClipPathUnits' => '345',
93
			'Indexed' => '346',
94
			'JPEGTables' => '347',
95
			'OPIProxy' => '351',
96
			'GlobalParametersIFD' => '400',
97
			'ProfileType' => '401',
98
			'FaxProfile' => '402',
99
			'CodingMethods' => '403',
100
			'VersionYear' => '404',
101
			'ModeNumber' => '405',
102
			'Decode' => '433',
103
			'DefaultImageColor' => '434',
104
			'T82Options' => '435',
105
			'JPEGTables' => '437',
106
			'JPEGProc' => '512',
107
			'ThumbnailOffset' => '513',
108
			'ThumbnailLength' => '514',
109
			'JPEGRestartInterval' => '515',
110
			'JPEGLosslessPredictors' => '517',
111
			'JPEGPointTransforms' => '518',
112
			'JPEGQTables' => '519',
113
			'JPEGDCTables' => '520',
114
			'JPEGACTables' => '521',
115
			'YCbCrCoefficients' => '529',
116
			'YCbCrSubSampling' => '530',
117
			'YCbCrPositioning' => '531',
118
			'ReferenceBlackWhite' => '532',
119
			'StripRowCounts' => '559',
120
			'ApplicationNotes' => '700',
121
			'USPTOMiscellaneous' => '999',
122
			'RelatedImageFileFormat' => '4096',
123
			'RelatedImageWidth' => '4097',
124
			'RelatedImageHeight' => '4098',
125
			'Rating' => '18246',
126
			'XP_DIP_XML' => '18247',
127
			'StitchInfo' => '18248',
128
			'RatingPercent' => '18249',
129
			'ImageID' => '32781',
130
			'WangTag1' => '32931',
131
			'WangAnnotation' => '32932',
132
			'WangTag3' => '32933',
133
			'WangTag4' => '32934',
134
			'Matteing' => '32995',
135
			'DataType' => '32996',
136
			'ImageDepth' => '32997',
137
			'TileDepth' => '32998',
138
			'Model2' => '33405',
139
			'CFARepeatPatternDim' => '33421',
140
			'CFAPattern2' => '33422',
141
			'BatteryLevel' => '33423',
142
			'KodakIFD' => '33424',
143
			'Copyright' => '33432',
144
			'ExposureTime' => '33434',
145
			'FNumber' => '33437',
146
			'MDFileTag' => '33445',
147
			'MDScalePixel' => '33446',
148
			'MDColorTable' => '33447',
149
			'MDLabName' => '33448',
150
			'MDSampleInfo' => '33449',
151
			'MDPrepDate' => '33450',
152
			'MDPrepTime' => '33451',
153
			'MDFileUnits' => '33452',
154
			'PixelScale' => '33550',
155
			'AdventScale' => '33589',
156
			'AdventRevision' => '33590',
157
			'UIC1Tag' => '33628',
158
			'UIC2Tag' => '33629',
159
			'UIC3Tag' => '33630',
160
			'UIC4Tag' => '33631',
161
			'IPTC-NAA' => '33723',
162
			'IntergraphPacketData' => '33918',
163
			'IntergraphFlagRegisters' => '33919',
164
			'IntergraphMatrix' => '33920',
165
			'INGRReserved' => '33921',
166
			'ModelTiePoint' => '33922',
167
			'Site' => '34016',
168
			'ColorSequence' => '34017',
169
			'IT8Header' => '34018',
170
			'RasterPadding' => '34019',
171
			'BitsPerRunLength' => '34020',
172
			'BitsPerExtendedRunLength' => '34021',
173
			'ColorTable' => '34022',
174
			'ImageColorIndicator' => '34023',
175
			'BackgroundColorIndicator' => '34024',
176
			'ImageColorValue' => '34025',
177
			'BackgroundColorValue' => '34026',
178
			'PixelIntensityRange' => '34027',
179
			'TransparencyIndicator' => '34028',
180
			'ColorCharacterization' => '34029',
181
			'HCUsage' => '34030',
182
			'TrapIndicator' => '34031',
183
			'CMYKEquivalent' => '34032',
184
			'SEMInfo' => '34118',
185
			'AFCP_IPTC' => '34152',
186
			'PixelMagicJBIGOptions' => '34232',
187
			'ModelTransform' => '34264',
188
			'WB_GRGBLevels' => '34306',
189
			'LeafData' => '34310',
190
			'PhotoshopSettings' => '34377',
191
			'ExifOffset' => '34665',
192
			'ICC_Profile' => '34675',
193
			'TIFF_FXExtensions' => '34687',
194
			'MultiProfiles' => '34688',
195
			'SharedData' => '34689',
196
			'T88Options' => '34690',
197
			'ImageLayer' => '34732',
198
			'GeoTiffDirectory' => '34735',
199
			'GeoTiffDoubleParams' => '34736',
200
			'GeoTiffAsciiParams' => '34737',
201
			'ExposureProgram' => '34850',
202
			'SpectralSensitivity' => '34852',
203
			'GPSInfo' => '34853',
204
			'ISO' => '34855',
205
			'Opto-ElectricConvFactor' => '34856',
206
			'Interlace' => '34857',
207
			'TimeZoneOffset' => '34858',
208
			'SelfTimerMode' => '34859',
209
			'SensitivityType' => '34864',
210
			'StandardOutputSensitivity' => '34865',
211
			'RecommendedExposureIndex' => '34866',
212
			'ISOSpeed' => '34867',
213
			'ISOSpeedLatitudeyyy' => '34868',
214
			'ISOSpeedLatitudezzz' => '34869',
215
			'FaxRecvParams' => '34908',
216
			'FaxSubAddress' => '34909',
217
			'FaxRecvTime' => '34910',
218
			'LeafSubIFD' => '34954',
219
			'ExifVersion' => '36864',
220
			'DateTimeOriginal' => '36867',
221
			'CreateDate' => '36868',
222
			'ComponentsConfiguration' => '37121',
223
			'CompressedBitsPerPixel' => '37122',
224
			'ShutterSpeedValue' => '37377',
225
			'ApertureValue' => '37378',
226
			'BrightnessValue' => '37379',
227
			'ExposureCompensation' => '37380',
228
			'MaxApertureValue' => '37381',
229
			'SubjectDistance' => '37382',
230
			'MeteringMode' => '37383',
231
			'LightSource' => '37384',
232
			'Flash' => '37385',
233
			'FocalLength' => '37386',
234
			'FlashEnergy' => '37387',
235
			'SpatialFrequencyResponse' => '37388',
236
			'Noise' => '37389',
237
			'FocalPlaneXResolution' => '37390',
238
			'FocalPlaneYResolution' => '37391',
239
			'FocalPlaneResolutionUnit' => '37392',
240
			'ImageNumber' => '37393',
241
			'SecurityClassification' => '37394',
242
			'ImageHistory' => '37395',
243
			'SubjectArea' => '37396',
244
			'ExposureIndex' => '37397',
245
			'TIFF-EPStandardID' => '37398',
246
			'SensingMethod' => '37399',
247
			'CIP3DataFile' => '37434',
248
			'CIP3Sheet' => '37435',
249
			'CIP3Side' => '37436',
250
			'StoNits' => '37439',
251
			'MakerNoteCanon' => '37500',
252
			'UserComment' => '37510',
253
			'SubSecTime' => '37520',
254
			'SubSecTimeOriginal' => '37521',
255
			'SubSecTimeDigitized' => '37522',
256
			'MSDocumentText' => '37679',
257
			'MSPropertySetStorage' => '37680',
258
			'MSDocumentTextPosition' => '37681',
259
			'ImageSourceData' => '37724',
260
			'XPTitle' => '40091',
261
			'XPComment' => '40092',
262
			'XPAuthor' => '40093',
263
			'XPKeywords' => '40094',
264
			'XPSubject' => '40095',
265
			'FlashpixVersion' => '40960',
266
			'ColorSpace' => '40961',
267
			'ExifImageWidth' => '40962',
268
			'ExifImageHeight' => '40963',
269
			'RelatedSoundFile' => '40964',
270
			'InteropOffset' => '40965',
271
			'FlashEnergy' => '41483',
272
			'SpatialFrequencyResponse' => '41484',
273
			'Noise' => '41485',
274
			'FocalPlaneXResolution' => '41486',
275
			'FocalPlaneYResolution' => '41487',
276
			'FocalPlaneResolutionUnit' => '41488',
277
			'ImageNumber' => '41489',
278
			'SecurityClassification' => '41490',
279
			'ImageHistory' => '41491',
280
			'SubjectLocation' => '41492',
281
			'ExposureIndex' => '41493',
282
			'TIFF-EPStandardID' => '41494',
283
			'SensingMethod' => '41495',
284
			'FileSource' => '41728',
285
			'SceneType' => '41729',
286
			'CFAPattern' => '41730',
287
			'CustomRendered' => '41985',
288
			'ExposureMode' => '41986',
289
			'WhiteBalance' => '41987',
290
			'DigitalZoomRatio' => '41988',
291
			'FocalLengthIn35mmFormat' => '41989',
292
			'SceneCaptureType' => '41990',
293
			'GainControl' => '41991',
294
			'Contrast' => '41992',
295
			'Saturation' => '41993',
296
			'Sharpness' => '41994',
297
			'DeviceSettingDescription' => '41995',
298
			'SubjectDistanceRange' => '41996',
299
			'ImageUniqueID' => '42016',
300
			'OwnerName' => '42032',
301
			'SerialNumber' => '42033',
302
			'LensInfo' => '42034',
303
			'LensMake' => '42035',
304
			'LensModel' => '42036',
305
			'LensSerialNumber' => '42037',
306
			'GDALMetadata' => '42112',
307
			'GDALNoData' => '42113',
308
			'Gamma' => '42240',
309
			'ExpandSoftware' => '44992',
310
			'ExpandLens' => '44993',
311
			'ExpandFilm' => '44994',
312
			'ExpandFilterLens' => '44995',
313
			'ExpandScanner' => '44996',
314
			'ExpandFlashLamp' => '44997',
315
			'PixelFormat' => '48129',
316
			'Transformation' => '48130',
317
			'Uncompressed' => '48131',
318
			'ImageType' => '48132',
319
			'ImageWidth' => '48256',
320
			'ImageHeight' => '48257',
321
			'WidthResolution' => '48258',
322
			'HeightResolution' => '48259',
323
			'ImageOffset' => '48320',
324
			'ImageByteCount' => '48321',
325
			'AlphaOffset' => '48322',
326
			'AlphaByteCount' => '48323',
327
			'ImageDataDiscard' => '48324',
328
			'AlphaDataDiscard' => '48325',
329
			'OceScanjobDesc' => '50215',
330
			'OceApplicationSelector' => '50216',
331
			'OceIDNumber' => '50217',
332
			'OceImageLogic' => '50218',
333
			'Annotations' => '50255',
334
			'PrintIM' => '50341',
335
			'USPTOOriginalContentType' => '50560',
336
			'DNGVersion' => '50706',
337
			'DNGBackwardVersion' => '50707',
338
			'UniqueCameraModel' => '50708',
339
			'LocalizedCameraModel' => '50709',
340
			'CFAPlaneColor' => '50710',
341
			'CFALayout' => '50711',
342
			'LinearizationTable' => '50712',
343
			'BlackLevelRepeatDim' => '50713',
344
			'BlackLevel' => '50714',
345
			'BlackLevelDeltaH' => '50715',
346
			'BlackLevelDeltaV' => '50716',
347
			'WhiteLevel' => '50717',
348
			'DefaultScale' => '50718',
349
			'DefaultCropOrigin' => '50719',
350
			'DefaultCropSize' => '50720',
351
			'ColorMatrix1' => '50721',
352
			'ColorMatrix2' => '50722',
353
			'CameraCalibration1' => '50723',
354
			'CameraCalibration2' => '50724',
355
			'ReductionMatrix1' => '50725',
356
			'ReductionMatrix2' => '50726',
357
			'AnalogBalance' => '50727',
358
			'AsShotNeutral' => '50728',
359
			'AsShotWhiteXY' => '50729',
360
			'BaselineExposure' => '50730',
361
			'BaselineNoise' => '50731',
362
			'BaselineSharpness' => '50732',
363
			'BayerGreenSplit' => '50733',
364
			'LinearResponseLimit' => '50734',
365
			'CameraSerialNumber' => '50735',
366
			'DNGLensInfo' => '50736',
367
			'ChromaBlurRadius' => '50737',
368
			'AntiAliasStrength' => '50738',
369
			'ShadowScale' => '50739',
370
			'SR2Private' => '50740',
371
			'MakerNoteSafety' => '50741',
372
			'RawImageSegmentation' => '50752',
373
			'CalibrationIlluminant1' => '50778',
374
			'CalibrationIlluminant2' => '50779',
375
			'BestQualityScale' => '50780',
376
			'RawDataUniqueID' => '50781',
377
			'AliasLayerMetadata' => '50784',
378
			'OriginalRawFileName' => '50827',
379
			'OriginalRawFileData' => '50828',
380
			'ActiveArea' => '50829',
381
			'MaskedAreas' => '50830',
382
			'AsShotICCProfile' => '50831',
383
			'AsShotPreProfileMatrix' => '50832',
384
			'CurrentICCProfile' => '50833',
385
			'CurrentPreProfileMatrix' => '50834',
386
			'ColorimetricReference' => '50879',
387
			'PanasonicTitle' => '50898',
388
			'PanasonicTitle2' => '50899',
389
			'CameraCalibrationSig' => '50931',
390
			'ProfileCalibrationSig' => '50932',
391
			'ProfileIFD' => '50933',
392
			'AsShotProfileName' => '50934',
393
			'NoiseReductionApplied' => '50935',
394
			'ProfileName' => '50936',
395
			'ProfileHueSatMapDims' => '50937',
396
			'ProfileHueSatMapData1' => '50938',
397
			'ProfileHueSatMapData2' => '50939',
398
			'ProfileToneCurve' => '50940',
399
			'ProfileEmbedPolicy' => '50941',
400
			'ProfileCopyright' => '50942',
401
			'ForwardMatrix1' => '50964',
402
			'ForwardMatrix2' => '50965',
403
			'PreviewApplicationName' => '50966',
404
			'PreviewApplicationVersion' => '50967',
405
			'PreviewSettingsName' => '50968',
406
			'PreviewSettingsDigest' => '50969',
407
			'PreviewColorSpace' => '50970',
408
			'PreviewDateTime' => '50971',
409
			'RawImageDigest' => '50972',
410
			'OriginalRawFileDigest' => '50973',
411
			'SubTileBlockSize' => '50974',
412
			'RowInterleaveFactor' => '50975',
413
			'ProfileLookTableDims' => '50981',
414
			'ProfileLookTableData' => '50982',
415
			'OpcodeList1' => '51008',
416
			'OpcodeList2' => '51009',
417
			'OpcodeList3' => '51022',
418
			'NoiseProfile' => '51041',
419
			'Padding' => '59932',
420
			'OffsetSchema' => '59933',
421
			'OwnerName' => '65000',
422
			'SerialNumber' => '65001',
423
			'Lens' => '65002',
424
			'KDC_IFD' => '65024',
425
			'RawFile' => '65100',
426
			'Converter' => '65101',
427
			'WhiteBalance' => '65102',
428
			'Exposure' => '65105',
429
			'Shadows' => '65106',
430
			'Brightness' => '65107',
431
			'Contrast' => '65108',
432
			'Saturation' => '65109',
433
			'Sharpness' => '65110',
434
			'Smoothness' => '65111',
435
			'MoireFilter' => '65112',
436
	);
437
 
438
	public function extraireMetadonnees($cheminImage) {
439
		if ($this->peutUtiliserExifTool()) {
440
			$this->meta = $this->decoderMetadonneesExifTool($cheminImage);
970 aurelien 441
		} else {
1155 jpm 442
			$this->meta = $this->decoderMetadonneesBasique($cheminImage);
970 aurelien 443
		}
1155 jpm 444
 
445
		$metadonnees = array();
3577 killian 446
		$metadonnees['date_shot'] = $this->obtenirDatePriseDeVue() ?: null;
3560 killian 447
		$metadonnees['size'] = filesize($cheminImage);
970 aurelien 448
		return $metadonnees;
623 aurelien 449
	}
1155 jpm 450
 
451
	private function peutUtiliserExifTool() {
452
		// TODO indiquer ceci dans un fichier de config
453
		return file_exists('/usr/bin/exiftool') && is_executable('/usr/bin/exiftool');
623 aurelien 454
	}
1155 jpm 455
 
456
	private function decoderMetadonneesExifTool($cheminImage) {
970 aurelien 457
		$metadata = array();
2145 aurelien 458
		$res = exec('/usr/bin/exiftool -g -D "'.$cheminImage.'"', $metadata);
1155 jpm 459
 
970 aurelien 460
		$metadata_decodees = array();
461
		$categorie = '';
462
		foreach($metadata as &$data) {
1155 jpm 463
			if ($this->estUnSeparateurCategorieExifTool($data)) {
464
				$categorie = trim(str_replace('----', '', $data));
970 aurelien 465
			} else {
466
				$data_decodee = $this->parserValeurMetadonneeExifTool($data);
467
				$cle_metadonnee = str_replace(' ', '', $data_decodee['cle']);
468
				$metadata_decodees[$categorie][$cle_metadonnee] = $data_decodee;
469
			}
470
		}
471
		return $metadata_decodees;
472
	}
1155 jpm 473
 
970 aurelien 474
	private function estUnSeparateurCategorieExifTool($data) {
1155 jpm 475
		return preg_match('^---- (.)* ----^',$data);
970 aurelien 476
	}
1155 jpm 477
 
970 aurelien 478
	private function parserValeurMetadonneeExifTool($data) {
988 aurelien 479
		$cle_valeur = explode(':',$data,2);
1155 jpm 480
 
970 aurelien 481
		$valeur = '';
482
		if(count($cle_valeur) == 2) {
483
			$valeur	= trim($cle_valeur[1]);
484
		}
1155 jpm 485
 
970 aurelien 486
		$id_cle = explode(' ',trim($cle_valeur[0]),2);
1155 jpm 487
 
970 aurelien 488
		$id_cle[1] = str_replace(array('-','/'),'',$id_cle[1]);
1155 jpm 489
 
970 aurelien 490
		$cle_id_valeur = array('cle' => $id_cle[1], 'id' => str_replace('-','',$id_cle[0]), 'valeur' => $valeur);
1155 jpm 491
		return $cle_id_valeur;
970 aurelien 492
	}
493
 
1155 jpm 494
	public function decoderMetadonneesBasique($chemin_fichier) {
2460 jpm 495
		$exif = @exif_read_data($chemin_fichier, "EXIF,COMPUTED,IFD0,FILE,COMMENT", true, false);
988 aurelien 496
 
2460 jpm 497
		// tant pis pour les makernote et xmp, les décoder demande trop de librairies externes, autant installer exiftool alors
498
		$metadonnees = array();
988 aurelien 499
		$metadonnees['XMP'] = array();
500
		unset($metadonnees['EXIF']['MakerNote']);
501
		$metadonnees['MAKERNOTE'] = array();
1357 aurelien 502
		$metadonnees_non_formatees = array();
503
		if(isset($exif['EXIF'])) {
504
			$metadonnees_non_formatees = array_merge($metadonnees_non_formatees, $exif['EXIF']);
505
		}
506
		if(isset($exif['IFD0'])) {
507
			$metadonnees_non_formatees = array_merge($metadonnees_non_formatees, $exif['IFD0']);
508
		}
1566 jpm 509
		$metadonnees['EXIF'] = $this->formaterTableauExif($metadonnees_non_formatees);
2460 jpm 510
		$metadonnees['IPTC'] = $this->extraireIptc($chemin_fichier);
511
		$metadonnees['File'] = array(
512
			'ImageWidth' => array('id' => '', 'valeur' => $exif['COMPUTED']['Width']),
1155 jpm 513
			'ImageHeight' => array('id' => '', 'valeur' => $exif['COMPUTED']['Height']));
2460 jpm 514
		return $metadonnees ;
515
	}
1155 jpm 516
 
517
 
518
 
519
 
2460 jpm 520
	private function obtenirDatePriseDeVue() {
521
		$date = isset($this->meta['EXIF']['DateTimeOriginal']) ? $this->meta['EXIF']['DateTimeOriginal']['valeur'] : '';
522
		return $date;
523
	}
1155 jpm 524
 
3577 killian 525
}