Subversion Repositories eFlore/Applications.cel

Rev

Rev 2459 | Rev 3534 | Go to most recent revision | Details | Compare with Previous | 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();
446
		$metadonnees['hauteur'] = $this->obtenirHauteur();
447
		$metadonnees['largeur'] = $this->obtenirLargeur();
448
		$metadonnees['date_prise_de_vue'] = $this->obtenirDatePriseDeVue();
449
		$metadonnees['appareil_fabriquant'] = $this->obtenirAppareilFabricant();
450
		$metadonnees['appareil_modele'] = $this->obtenirAppareilModele();
451
		$metadonnees['meta_exif'] = $this->convertirMetaVersXML('EXIF');
452
		$metadonnees['meta_iptc'] = $this->convertirMetaVersXML('IPTC');
453
		$metadonnees['meta_xmp'] = $this->convertirMetaVersXML('XMP');
454
		$metadonnees['meta_makernote'] = $this->convertirMetaVersXML('MAKERNOTE');
970 aurelien 455
		return $metadonnees;
623 aurelien 456
	}
1155 jpm 457
 
458
	private function peutUtiliserExifTool() {
459
		// TODO indiquer ceci dans un fichier de config
460
		return file_exists('/usr/bin/exiftool') && is_executable('/usr/bin/exiftool');
623 aurelien 461
	}
1155 jpm 462
 
463
	private function decoderMetadonneesExifTool($cheminImage) {
970 aurelien 464
		$metadata = array();
2145 aurelien 465
		$res = exec('/usr/bin/exiftool -g -D "'.$cheminImage.'"', $metadata);
1155 jpm 466
 
970 aurelien 467
		$metadata_decodees = array();
468
		$categorie = '';
469
		foreach($metadata as &$data) {
1155 jpm 470
			if ($this->estUnSeparateurCategorieExifTool($data)) {
471
				$categorie = trim(str_replace('----', '', $data));
970 aurelien 472
			} else {
473
				$data_decodee = $this->parserValeurMetadonneeExifTool($data);
474
				$cle_metadonnee = str_replace(' ', '', $data_decodee['cle']);
475
				$metadata_decodees[$categorie][$cle_metadonnee] = $data_decodee;
476
			}
477
		}
478
		return $metadata_decodees;
479
	}
1155 jpm 480
 
970 aurelien 481
	private function estUnSeparateurCategorieExifTool($data) {
1155 jpm 482
		return preg_match('^---- (.)* ----^',$data);
970 aurelien 483
	}
1155 jpm 484
 
970 aurelien 485
	private function parserValeurMetadonneeExifTool($data) {
988 aurelien 486
		$cle_valeur = explode(':',$data,2);
1155 jpm 487
 
970 aurelien 488
		$valeur = '';
489
		if(count($cle_valeur) == 2) {
490
			$valeur	= trim($cle_valeur[1]);
491
		}
1155 jpm 492
 
970 aurelien 493
		$id_cle = explode(' ',trim($cle_valeur[0]),2);
1155 jpm 494
 
970 aurelien 495
		$id_cle[1] = str_replace(array('-','/'),'',$id_cle[1]);
1155 jpm 496
 
970 aurelien 497
		$cle_id_valeur = array('cle' => $id_cle[1], 'id' => str_replace('-','',$id_cle[0]), 'valeur' => $valeur);
1155 jpm 498
		return $cle_id_valeur;
970 aurelien 499
	}
500
 
1155 jpm 501
	public function decoderMetadonneesBasique($chemin_fichier) {
2460 jpm 502
		$exif = @exif_read_data($chemin_fichier, "EXIF,COMPUTED,IFD0,FILE,COMMENT", true, false);
988 aurelien 503
 
2460 jpm 504
		// tant pis pour les makernote et xmp, les décoder demande trop de librairies externes, autant installer exiftool alors
505
		$metadonnees = array();
988 aurelien 506
		$metadonnees['XMP'] = array();
507
		unset($metadonnees['EXIF']['MakerNote']);
508
		$metadonnees['MAKERNOTE'] = array();
1357 aurelien 509
		$metadonnees_non_formatees = array();
510
		if(isset($exif['EXIF'])) {
511
			$metadonnees_non_formatees = array_merge($metadonnees_non_formatees, $exif['EXIF']);
512
		}
513
		if(isset($exif['IFD0'])) {
514
			$metadonnees_non_formatees = array_merge($metadonnees_non_formatees, $exif['IFD0']);
515
		}
1566 jpm 516
		$metadonnees['EXIF'] = $this->formaterTableauExif($metadonnees_non_formatees);
2460 jpm 517
		$metadonnees['IPTC'] = $this->extraireIptc($chemin_fichier);
518
		$metadonnees['File'] = array(
519
			'ImageWidth' => array('id' => '', 'valeur' => $exif['COMPUTED']['Width']),
1155 jpm 520
			'ImageHeight' => array('id' => '', 'valeur' => $exif['COMPUTED']['Height']));
2460 jpm 521
		return $metadonnees ;
522
	}
1155 jpm 523
 
2460 jpm 524
	private function formaterTableauExif(&$tableau) {
525
		$tableau_exif_formate = array();
1155 jpm 526
 
2460 jpm 527
		foreach ($tableau as $nom_tag => $valeur) {
528
			$id = '';
529
			if (isset($this->tableau_ids_tags_exif[$nom_tag])) {
530
				$id = $this->tableau_ids_tags_exif[$nom_tag];
531
			}
532
			$tableau_exif_formate[$nom_tag] = array('id' => $id, 'valeur' => $valeur);
533
		}
1155 jpm 534
 
2460 jpm 535
		return $tableau_exif_formate;
536
	}
1155 jpm 537
 
2460 jpm 538
	/**
539
	 * Extraction des metadonnées iptc
540
	 */
541
	public function extraireIptc($chemin_fichier) {
542
		$meta = array();
1155 jpm 543
 
2460 jpm 544
		// getimagesize renvoie les infos iptc dans le tableau info
545
		$info = array();
546
		$size = getimagesize($chemin_fichier, $info);
1155 jpm 547
 
2460 jpm 548
		// s'il existe
549
		if (isset($info['APP13'])) {
550
			// on parse les donnees
551
			$iptc = iptcparse($info['APP13']);
552
			if ($iptc) {
553
				// et on les analyse
554
				foreach ($iptc as $marker => $section) {
555
					foreach ($section as $nom => $val) {
556
						// pour remplir le tableau de donnees
557
						$this->decoderValeurIptc($marker, $val, $meta);
558
					}
559
				}
560
			}
561
		}
562
		return $meta;
563
	}
1155 jpm 564
 
2460 jpm 565
	/**
566
	* Stocke une valeur de metadonnées iptc dans le champ du tableau correspondant
567
	* @param String $nom nom de la valeur
568
	* @param String $val valeur
569
	* @param String $data référence vers le tableau où la donnée sera stockée
570
	**/
571
	private function decoderValeurIptc($nom, $val, &$data_tab) {
572
		switch ($nom) {
573
			case "2#005" :// mots cles iptc
574
				$data_tab['Category'] = array('id' => '5', 'valeur' => $val);
575
				break;
576
			case "2#080" :// champ by line
577
				$data_tab['By-Line']  = array('id' => '80', 'valeur' => $val);
578
				break ;
579
			case "2#085" :// champ by line titre
580
				$data_tab['By-LineTitle'] = array('id' => '85', 'valeur' => $val);
581
				break ;
582
			case "2#090" :// ville
583
				$data_tab['City'] = array('id' => '90', 'valeur' => $val);
584
				break ;
585
			case "2#092" :// sous location
586
				$data_tab['SubLocation'] = array('id' => '92', 'valeur' => $val);
587
				break ;
588
			case "2#095" :// etat (pour les us)
589
				$data_tab['ProvinceState'] = array('id' => '95', 'valeur' => $val);
590
				break ;
591
			case "2#100" :// code pays
592
				$data_tab['CountryPrimaryLocationCode'] = array('id' => '100', 'valeur' => $val);
593
				break ;
594
			case "2#101" :// code pays
595
				$data_tab['CountryName'] = array('id' => '101', 'valeur' => $val);
596
				break ;
597
			case "2#105" :// titre principal
598
				$data_tab['Headline'] = array('id' => '105', 'valeur' => $val);
599
				break ;
600
			case "2#110" :// credit
601
				$data_tab['Credit'] = array('id' => '110', 'valeur' => $val);
602
				break ;
603
			case "2#116" :// copyright
604
				$data_tab['CopyrightNotice'] = array('id' => '116', 'valeur' => $val);
605
				break ;
606
			case "2#118" :// contact
607
				$data_tab['Contact'] = array('id' => '118', 'valeur' => $val);
608
				break ;
609
			default:
610
				unset($data_tab['nom']);
611
		}
612
	}
1155 jpm 613
 
2460 jpm 614
	private function obtenirHauteur() {
615
		$hauteur = isset($this->meta['File']['ImageHeight']) ? $this->meta['File']['ImageHeight']['valeur'] : '';
616
		return $hauteur;
617
	}
1155 jpm 618
 
2460 jpm 619
	private function obtenirLargeur() {
620
		$largeur = isset($this->meta['File']['ImageWidth']) ? $this->meta['File']['ImageWidth']['valeur'] : '';
621
		return $largeur;
622
	}
1155 jpm 623
 
2460 jpm 624
	private function obtenirDatePriseDeVue() {
625
		$date = isset($this->meta['EXIF']['DateTimeOriginal']) ? $this->meta['EXIF']['DateTimeOriginal']['valeur'] : '';
626
		return $date;
627
	}
1155 jpm 628
 
2460 jpm 629
	private function obtenirAppareilFabricant() {
630
		$fabriquant = isset($this->meta['EXIF']['Make']) ? $this->meta['EXIF']['Make']['valeur'] : '';
631
		return $fabriquant;
632
	}
1155 jpm 633
 
2460 jpm 634
	private function obtenirAppareilModele() {
635
		$modele = isset($this->meta['EXIF']['CameraModelName']) ? $this->meta['EXIF']['CameraModelName']['valeur'] : '';
636
		return $modele;
637
	}
1155 jpm 638
 
2460 jpm 639
	private function convertirMetaVersXML($type) {
640
		$xml = null;
641
		if (isset($this->meta[$type])) {
642
			$racine = strtolower($type);
1155 jpm 643
 
2460 jpm 644
			$xml = '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
645
			$xml .= "<$racine>"."\n";
646
			foreach ($this->meta[$type] as $prop => &$valeur) {
647
				$xml .= '<'.$prop.' id="'.$valeur['id'].'">'.$valeur['valeur'].'</'.$prop.'>'."\n";
648
			}
649
			$xml .= "</$racine>";
650
		}
651
		return $xml;
652
	}
653
}