Subversion Repositories eFlore/Applications.cel

Rev

Rev 2145 | Rev 2460 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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