forked from evanhunter/PJMT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhotoshop_File_Info.php
2498 lines (1983 loc) · 105 KB
/
Photoshop_File_Info.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/******************************************************************************
*
* Filename: Photoshop_File_Info.php
*
* Description: Provides functions that mimic the way Photoshop reads and writes
* metadata in it's 'File Info' dialog
*
* Author: Evan Hunter
*
* Date: 11/11/2004
*
* Project: JPEG Metadata
*
* Revision: 1.11
* Changes: 1.10 -> 1.11 : Changed displayed toolkit version numbers to reference Toolkit_Version.php
*
* URL: http://electronics.ozhiker.com
*
* License: This file is part of the PHP JPEG Metadata Toolkit.
*
* The PHP JPEG Metadata Toolkit is free software; you can
* redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* The PHP JPEG Metadata Toolkit is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public
* License along with the PHP JPEG Metadata Toolkit; if not,
* write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* If you require a different license for commercial or other
* purposes, please contact the author: [email protected]
*
******************************************************************************/
// TODO: XMP sections: XAPMM, TIFF, EXIF
include 'Toolkit_Version.php'; // Change: added as of version 1.11
/******************************************************************************
* Global Variable: Software Name
*
* Contents: The string that is appended to fields which store the name of
* the software editor.
*
******************************************************************************/
$GLOBALS[ "Software Name" ] = "(PHP JPEG Metadata Toolkit v" . $GLOBALS['Toolkit_Version'] . ")"; // Change: Changed version numbers to reference Toolkit_Version.php - as of version 1.11
/******************************************************************************
* End of Global Variable: Software Name
******************************************************************************/
/******************************************************************************
*
* Function: get_photoshop_file_info
*
* Description: Retrieves Photoshop 'File Info' metadata in the same way that Photoshop
* does. The results are returned in an array as below:
*
* $file_info_array = array(
* "title" => "",
* "author" => "",
* "authorsposition" => "", // Note: Not used in Photoshop 7 or higher
* "caption" => "",
* "captionwriter" => "",
* "jobname" => "", // Note: Not used in Photoshop CS
* "copyrightstatus" => "",
* "copyrightnotice" => "",
* "ownerurl" => "",
* "keywords" => array( 0 => "", 1 => "", ... ),
* "category" => "", // Note: Max 3 characters
* "supplementalcategories" => array( 0 => "", 1 => "", ... ),
* "date" => "", // Note: DATE MUST BE IN YYYY-MM-DD format
* "city" => "",
* "state" => "",
* "country" => "",
* "credit" => "",
* "source" => "",
* "headline" => "",
* "instructions" => "",
* "transmissionreference" => "",
* "urgency" => "" );
*
* Parameters: Exif_array - an array containing the EXIF information to be
* searched, as retrieved by get_EXIF_JPEG. (saves having to parse the EXIF again)
* XMP_array - an array containing the XMP information to be
* searched, as retrieved by read_XMP_array_from_text. (saves having to parse the XMP again)
* IRB_array - an array containing the Photoshop IRB information
* to be searched, as retrieved by get_Photoshop_IRB. (saves having to parse the IRB again)
*
* Returns: outputarray - an array as above, containing the Photoshop File Info data
*
******************************************************************************/
function get_photoshop_file_info( $Exif_array, $XMP_array, $IRB_array )
{
// Create a blank array to receive the output
$outputarray = array(
"title" => "",
"author" => "",
"authorsposition" => "",
"caption" => "",
"captionwriter" => "",
"jobname" => "",
"copyrightstatus" => "",
"copyrightnotice" => "",
"ownerurl" => "",
"keywords" => array(),
"category" => "",
"supplementalcategories" => array(),
"date" => "",
"city" => "",
"state" => "",
"country" => "",
"credit" => "",
"source" => "",
"headline" => "",
"instructions" => "",
"transmissionreference" => "",
"urgency" => "" );
/***************************************/
// XMP Processing
// Retrieve the dublin core section from the XMP header
// Extract the Dublin Core section from the XMP
$dublincore_block = find_XMP_block( $XMP_array, "dc" );
// Check that the Dublin Core section exists
if ( $dublincore_block != FALSE )
{
// Dublin Core Description Field contains caption
// Extract Description
$Item = find_XMP_item( $dublincore_block, "dc:description" );
// Check if Description Tag existed
if ( $Item != FALSE )
{
// Ensure that the Description value exists and save it.
if ( ( array_key_exists( 'children', $Item ) ) &&
( $Item['children'][0]['tag'] == "rdf:Alt" ) &&
( array_key_exists( 'value', $Item['children'][0]['children'][0] ) ) )
{
$outputarray = add_to_field( $outputarray, 'caption' , HTML_UTF8_Escape( $Item['children'][0]['children'][0]['value'] ), "\n" );
}
}
/***************************************/
// Dublin Core Creator Field contains author
// Extract Description
$Item = find_XMP_item( $dublincore_block, "dc:creator" );
// Check if Creator Tag existed
if ( $Item != FALSE )
{
// Ensure that the Creator value exists and save it.
if ( ( array_key_exists( 'children', $Item ) ) &&
( $Item['children'][0]['tag'] =="rdf:Seq" ) &&
( array_key_exists( 'value', $Item['children'][0]['children'][0] ) ) )
{
$outputarray = add_to_field( $outputarray, 'author' , HTML_UTF8_Escape( $Item['children'][0]['children'][0]['value'] ), "\n" );
}
}
/***************************************/
// Dublin Core Title Field contains title
// Extract Title
$Item = find_XMP_item( $dublincore_block, "dc:title" );
// Check if Title Tag existed
if ( $Item != FALSE )
{
// Ensure that the Title value exists and save it.
if ( ( array_key_exists( 'children', $Item ) ) &&
( $Item['children'][0]['tag'] =="rdf:Alt" ) &&
( array_key_exists( 'value', $Item['children'][0]['children'][0] ) ) )
{
$outputarray = add_to_field( $outputarray, 'title' , HTML_UTF8_Escape( $Item['children'][0]['children'][0]['value'] ), "," );
}
}
/***************************************/
// Dublin Core Rights Field contains copyrightnotice
// Extract Rights
$Item = find_XMP_item( $dublincore_block, "dc:rights" );
// Check if Rights Tag existed
if ( $Item != FALSE )
{
// Ensure that the Rights value exists and save it.
if ( ( array_key_exists( 'children', $Item ) ) &&
( $Item['children'][0]['tag'] =="rdf:Alt" ) &&
( array_key_exists( 'value', $Item['children'][0]['children'][0] ) ) )
{
$outputarray = add_to_field( $outputarray, 'copyrightnotice' , HTML_UTF8_Escape( $Item['children'][0]['children'][0]['value'] ), "," );
}
}
/***************************************/
// Dublin Core Subject Field contains keywords
// Extract Subject
$Item = find_XMP_item( $dublincore_block, "dc:subject" );
// Check if Subject Tag existed
if ( $Item != FALSE )
{
// Ensure that the Subject values exist
if ( ( array_key_exists( 'children', $Item ) ) && ( $Item['children'][0]['tag'] =="rdf:Bag" ) )
{
// Cycle through each Subject value and save them
foreach ( $Item['children'][0]['children'] as $keywords )
{
if ( ! in_array ( HTML_UTF8_Escape( $keywords['value'] ), $outputarray['keywords']))
{
if ( array_key_exists( 'value', $keywords ) )
{
$outputarray['keywords'][] = HTML_UTF8_Escape( $keywords['value'] );
}
}
}
}
}
}
/***************************************/
// Find the Photoshop Information within the XMP block
$photoshop_block = find_XMP_block( $XMP_array, "photoshop" );
// Check that the Photoshop Information exists
if ( $photoshop_block != FALSE )
{
// The Photoshop CaptionWriter tag contains captionwriter - Find it
$Item = find_XMP_item( $photoshop_block, "photoshop:CaptionWriter" );
// Check that the CaptionWriter Field exists and save the value
if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
{
$outputarray = add_to_field( $outputarray, 'captionwriter' , HTML_UTF8_Escape( $Item['value'] ), "," );
}
/***************************************/
// The Photoshop Headline tag contains headline - Find it
$Item = find_XMP_item( $photoshop_block, "photoshop:Headline" );
// Check that the Headline Field exists and save the value
if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
{
$outputarray = add_to_field( $outputarray, 'headline' , HTML_UTF8_Escape( $Item['value'] ), "," );
}
/***************************************/
// The Photoshop Instructions tag contains instructions - Find it
$Item = find_XMP_item( $photoshop_block, "photoshop:Instructions" );
// Check that the Instructions Field exists and save the value
if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
{
$outputarray = add_to_field( $outputarray, 'instructions' , HTML_UTF8_Escape( $Item['value'] ), "\n" );
}
/***************************************/
// The Photoshop AuthorsPosition tag contains authorsposition - Find it
$Item = find_XMP_item( $photoshop_block, "photoshop:AuthorsPosition" );
// Check that the AuthorsPosition Field exists and save the value
if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
{
$outputarray = add_to_field( $outputarray, 'authorsposition' , HTML_UTF8_Escape( $Item['value'] ), "," );
}
/***************************************/
// The Photoshop Credit tag contains credit - Find it
$Item = find_XMP_item( $photoshop_block, "photoshop:Credit" );
// Check that the Credit Field exists and save the value
if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
{
$outputarray = add_to_field( $outputarray, 'credit' , HTML_UTF8_Escape( $Item['value'] ), "," );
}
/***************************************/
// The Photoshop Source tag contains source - Find it
$Item = find_XMP_item( $photoshop_block, "photoshop:Source" );
// Check that the Credit Field exists and save the value
if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
{
$outputarray = add_to_field( $outputarray, 'source' , HTML_UTF8_Escape( $Item['value'] ), "," );
}
/***************************************/
// The Photoshop City tag contains city - Find it
$Item = find_XMP_item( $photoshop_block, "photoshop:City" );
// Check that the City Field exists and save the value
if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
{
$outputarray = add_to_field( $outputarray, 'city' , HTML_UTF8_Escape( $Item['value'] ), "," );
}
/***************************************/
// The Photoshop State tag contains state - Find it
$Item = find_XMP_item( $photoshop_block, "photoshop:State" );
// Check that the State Field exists and save the value
if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
{
$outputarray = add_to_field( $outputarray, 'state' , HTML_UTF8_Escape( $Item['value'] ), "," );
}
/***************************************/
// The Photoshop Country tag contains country - Find it
$Item = find_XMP_item( $photoshop_block, "photoshop:Country" );
// Check that the Country Field exists and save the value
if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
{
$outputarray = add_to_field( $outputarray, 'country' , HTML_UTF8_Escape( $Item['value'] ), "," );
}
/***************************************/
// The Photoshop TransmissionReference tag contains transmissionreference - Find it
$Item = find_XMP_item( $photoshop_block, "photoshop:TransmissionReference" );
// Check that the TransmissionReference Field exists and save the value
if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
{
$outputarray = add_to_field( $outputarray, 'transmissionreference' , HTML_UTF8_Escape( $Item['value'] ), "," );
}
/***************************************/
// The Photoshop Category tag contains category - Find it
$Item = find_XMP_item( $photoshop_block, "photoshop:Category" );
// Check that the TransmissionReference Field exists and save the value
if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
{
$outputarray = add_to_field( $outputarray, 'category' , HTML_UTF8_Escape( $Item['value'] ), "," );
}
/***************************************/
// The Photoshop DateCreated tag contains date - Find it
$Item = find_XMP_item( $photoshop_block, "photoshop:DateCreated" );
// Check that the DateCreated Field exists and save the value
if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
{
$outputarray = add_to_field( $outputarray, 'date' , HTML_UTF8_Escape( $Item['value'] ), "," );
}
/***************************************/
// The Photoshop Urgency tag contains urgency - Find it
$Item = find_XMP_item( $photoshop_block, "photoshop:Urgency" );
// Check that the Urgency Field exists and save the value
if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
{
$outputarray = add_to_field( $outputarray, 'urgency' , HTML_UTF8_Escape( $Item['value'] ), "," );
}
/***************************************/
// The Photoshop SupplementalCategories tag contains supplementalcategories - Find it
$Item = find_XMP_item( $photoshop_block, "photoshop:SupplementalCategories" );
// Check that the SupplementalCategories Field exists
if ( $Item != FALSE )
{
// Check that the values exist
if ( ( array_key_exists( 'children', $Item ) ) && ( $Item['children'][0]['tag'] =="rdf:Bag" ) )
{
// Cycle through the values and save them
foreach ( $Item['children'][0]['children'] as $sup_category )
{
if ( ( array_key_exists( 'value', $sup_category ) ) &&
( ! in_array ( HTML_UTF8_Escape( $sup_category['value'] ), $outputarray['supplementalcategories'])) )
{
if ( array_key_exists( 'value', $sup_category ) )
{
$outputarray['supplementalcategories'][] = HTML_UTF8_Escape( $sup_category['value'] );
}
}
}
}
}
}
/***************************************/
// Find the Job Reference Information within the XMP block
$job_block = find_XMP_block( $XMP_array, "xapBJ" );
// Check that the Job Reference Information exists
if ( $job_block != FALSE )
{
// The JobRef Field contains jobname - Find it
$Item = find_XMP_item( $job_block, "xapBJ:JobRef" );
// Check that the JobRef Field exists
if ( $Item != FALSE )
{
// Check that the value exists and save it
if ( ( array_key_exists( 'children', $Item ) ) &&
( $Item['children'][0]['tag'] =="rdf:Bag" ) &&
( array_key_exists( 'children', $Item['children'][0] ) ) &&
( $Item['children'][0]['children'][0]['tag'] =="rdf:li" ) &&
( array_key_exists( 'children', $Item['children'][0]['children'][0] ) ) &&
( $Item['children'][0]['children'][0]['children'][0]['tag'] =="stJob:name" ) &&
( array_key_exists( 'value', $Item['children'][0]['children'][0]['children'][0] ) ) )
{
$outputarray = add_to_field( $outputarray, 'jobname' , HTML_UTF8_Escape( $Item['children'][0]['children'][0]['children'][0]['value'] ), "," );
}
}
}
/***************************************/
// Find the Rights Information within the XMP block
$rights_block = find_XMP_block( $XMP_array, "xapRights" );
// Check that the Rights Information exists
if ( $rights_block != FALSE )
{
// The WebStatement Field contains ownerurl - Find it
$Item = find_XMP_item( $rights_block, "xapRights:WebStatement" );
// Check that the WebStatement Field exists and save the value
if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
{
$outputarray = add_to_field( $outputarray, 'ownerurl' , HTML_UTF8_Escape( $Item['value'] ), "\n" );
}
/***************************************/
// The Marked Field contains copyrightstatus - Find it
$Item = find_XMP_item( $rights_block, "xapRights:Marked" );
// Check that the Marked Field exists and save the value
if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
{
if ( $Item['value'] == "True" )
{
$outputarray = add_to_field( $outputarray, 'copyrightstatus' , "Copyrighted Work", "," );
}
else
{
$outputarray = add_to_field( $outputarray, 'copyrightstatus' , "Public Domain", "," );
}
}
}
/***************************************/
// Photoshop IRB Processing
// Check that the Photoshop IRB exists
if ( $IRB_array != FALSE )
{
// Create a translation table to convert carriage returns to linefeeds
$irbtrans = array("\x0d" => "\x0a");
// The Photoshop IRB Copyright flag (0x040A) contains copyrightstatus - find it
$IRB_copyright_flag = find_Photoshop_IRB_Resource( $IRB_array, 0x040A );
// Check if the Copyright flag Field exists, and save the value
if( $IRB_copyright_flag != FALSE )
{
// Check the value of the copyright flag
if ( hexdec( bin2hex( $IRB_copyright_flag['ResData'] ) ) == 1 )
{
// Save the value
$outputarray = add_to_field( $outputarray, 'copyrightstatus' , "Copyrighted Work", "," );
}
else
{
// Do nothing - copyrightstatus will be set to unmarked if still blank at end
}
}
/***************************************/
// The Photoshop IRB URL (0x040B) contains ownerurl - find it
$IRB_url = find_Photoshop_IRB_Resource( $IRB_array, 0x040B );
// Check if the URL Field exists and save the value
if( $IRB_url != FALSE )
{
$outputarray = add_to_field( $outputarray, 'ownerurl' , strtr( $IRB_url['ResData'], $irbtrans ), "\n" );
}
/***************************************/
// Extract any IPTC block from the Photoshop IRB information
$IPTC_array = get_Photoshop_IPTC( $IRB_array );
// Check if the IPTC block exits
if ( ( $IPTC_array != FALSE ) && ( count( $IPTC_array ) != 0 ) )
{
// The IPTC Caption/Abstract Field contains caption - find it
$record = find_IPTC_Resource( $IPTC_array, "2:120" );
// Check if the Caption/Abstract Field exists and save the value
if ( $record != FALSE )
{
$outputarray = add_to_field( $outputarray, 'caption' , strtr( $record['RecData'], $irbtrans ), "\n" );
}
/***************************************/
// The IPTC Caption Writer/Editor Field contains captionwriter - find it
$record = find_IPTC_Resource( $IPTC_array, "2:122" );
// Check if the Caption Writer/Editor Field exists and save the value
if ( $record != FALSE )
{
$outputarray = add_to_field( $outputarray, 'captionwriter' , strtr( $record['RecData'], $irbtrans ), "\n" );
}
/***************************************/
// The IPTC Headline Field contains headline - find it
$record = find_IPTC_Resource( $IPTC_array, "2:105" );
// Check if the Headline Field exists and save the value
if ( $record != FALSE )
{
$outputarray = add_to_field( $outputarray, 'headline' , strtr( $record['RecData'], $irbtrans ), "\n" );
}
/***************************************/
// The IPTC Special Instructions Field contains instructions - find it
$record = find_IPTC_Resource( $IPTC_array, "2:40" );
// Check if the Special Instructions Field exists and save the value
if ( $record != FALSE )
{
$outputarray = add_to_field( $outputarray, 'instructions' , strtr( $record['RecData'], $irbtrans ), "\n" );
}
/***************************************/
// The IPTC By-Line Field contains author - find it
$record = find_IPTC_Resource( $IPTC_array, "2:80" );
// Check if the By-Line Field exists and save the value
if ( $record != FALSE )
{
$outputarray = add_to_field( $outputarray, 'author' , strtr( $record['RecData'], $irbtrans ), "\n" );
}
/***************************************/
// The IPTC By-Line Title Field contains authorsposition - find it
$record = find_IPTC_Resource( $IPTC_array, "2:85" );
// Check if the By-Line Title Field exists and save the value
if ( $record != FALSE )
{
$outputarray = add_to_field( $outputarray, 'authorsposition' , strtr( $record['RecData'], $irbtrans ), "\n" );
}
/***************************************/
// The IPTC Credit Field contains credit - find it
$record = find_IPTC_Resource( $IPTC_array, "2:110" );
// Check if the Credit Field exists and save the value
if ( $record != FALSE )
{
$outputarray = add_to_field( $outputarray, 'credit' , strtr( $record['RecData'], $irbtrans ), "\n" );
}
/***************************************/
// The IPTC Source Field contains source - find it
$record = find_IPTC_Resource( $IPTC_array, "2:115" );
// Check if the Source Field exists and save the value
if ( $record != FALSE )
{
$outputarray = add_to_field( $outputarray, 'source' , strtr( $record['RecData'], $irbtrans ), "\n" );
}
/***************************************/
// The IPTC Object Name Field contains title - find it
$record = find_IPTC_Resource( $IPTC_array, "2:05" );
// Check if the Object Name Field exists and save the value
if ( $record != FALSE )
{
$outputarray = add_to_field( $outputarray, 'title' , strtr( $record['RecData'], $irbtrans ), "\n" );
}
/***************************************/
// The IPTC Date Created Field contains date - find it
$record = find_IPTC_Resource( $IPTC_array, "2:55" );
// Check if the Date Created Field exists and save the value
if ( $record != FALSE )
{
$date_array = unpack( "a4Year/a2Month/A2Day", $record['RecData'] );
$tmpdate = $date_array['Year'] . "-" . $date_array['Month'] . "-" . $date_array['Day'];
$outputarray = add_to_field( $outputarray, 'date' , strtr( $tmpdate, $irbtrans ), "," );
}
/***************************************/
// The IPTC City Field contains city - find it
$record = find_IPTC_Resource( $IPTC_array, "2:90" );
// Check if the City Field exists and save the value
if ( $record != FALSE )
{
$outputarray = add_to_field( $outputarray, 'city' , strtr( $record['RecData'], $irbtrans ), "\n" );
}
/***************************************/
// The IPTC Province/State Field contains state - find it
$record = find_IPTC_Resource( $IPTC_array, "2:95" );
// Check if the Province/State Field exists and save the value
if ( $record != FALSE )
{
$outputarray = add_to_field( $outputarray, 'state' , strtr( $record['RecData'], $irbtrans ), "\n" );
}
/***************************************/
// The IPTC Country/Primary Location Name Field contains country - find it
$record = find_IPTC_Resource( $IPTC_array, "2:101" );
// Check if the Country/Primary Location Name Field exists and save the value
if ( $record != FALSE )
{
$outputarray = add_to_field( $outputarray, 'country' , strtr( $record['RecData'], $irbtrans ), "\n" );
}
/***************************************/
// The IPTC Original Transmission Reference Field contains transmissionreference - find it
$record = find_IPTC_Resource( $IPTC_array, "2:103" );
// Check if the Original Transmission Reference Field exists and save the value
if ( $record != FALSE )
{
$outputarray = add_to_field( $outputarray, 'transmissionreference' , strtr( $record['RecData'], $irbtrans ), "\n" );
}
/***************************************/
// The IPTC Category Field contains category - find it
$record = find_IPTC_Resource( $IPTC_array, "2:15" );
// Check if the Category Field exists and save the value
if ( $record != FALSE )
{
$outputarray = add_to_field( $outputarray, 'category' , strtr( $record['RecData'], $irbtrans ), "\n" );
}
/***************************************/
// Cycle through the IPTC records looking for Supplemental Category records
foreach ($IPTC_array as $record)
{
// Check if a Supplemental Category record has been found
if ( $record['IPTC_Type'] == "2:20" )
{
// A Supplemental Category record has been found, save it's value if the value doesn't already exist
if ( ! in_array ( $record['RecData'], $outputarray['supplementalcategories']))
{
$outputarray['supplementalcategories'][] = strtr( $record['RecData'], array("\x0a" => "", "\x0d" => "
") ) ;
}
}
}
/***************************************/
// The IPTC Urgency Field contains urgency - find it
$record = find_IPTC_Resource( $IPTC_array, "2:10" );
// Check if the Urgency Field exists and save the value
if ( $record != FALSE )
{
$outputarray = add_to_field( $outputarray, 'urgency' , strtr( $record['RecData'], $irbtrans ), "\n" );
}
/***************************************/
// Cycle through the IPTC records looking for Keywords records
foreach ($IPTC_array as $record)
{
// Check if a Keywords record has been found
if ( $record['IPTC_Type'] == "2:25" )
{
// A Keywords record has been found, save it's value if the value doesn't already exist
if ( ! in_array ( $record['RecData'], $outputarray['keywords']))
{
$outputarray['keywords'][] = strtr( $record['RecData'], array("\x0a" => "", "\x0d" => "
") ) ;
}
}
}
/***************************************/
// The IPTC Copyright Notice Field contains copyrightnotice - find it
$record = find_IPTC_Resource( $IPTC_array, "2:116" );
// Check if the Copyright Field exists and save the value
if ( $record != FALSE )
{
$outputarray = add_to_field( $outputarray, 'copyrightnotice' , strtr( $record['RecData'], $irbtrans ), "\n" );
}
}
}
/***************************************/
// EXIF Processing
// Retreive Information from the EXIF data if it exists
if ( ( $Exif_array != FALSE ) || ( count( $Exif_array ) == 0 ) )
{
// Check the Image Description Tag - it can contain the caption
if ( array_key_exists( 270, $Exif_array[0] ) )
{
$outputarray = add_to_field( $outputarray, 'caption' , $Exif_array[0][270]['Data'][0], "\n" );
}
/***************************************/
// Check the Copyright Information Tag - it contains the copyrightnotice
if ( array_key_exists( 33432, $Exif_array[0] ) )
{
$outputarray = add_to_field( $outputarray, 'copyrightnotice' , HTML_UTF8_UnEscape( $Exif_array[0][33432]['Data'][0] ), "\n" );
}
/***************************************/
// Check the Artist Name Tag - it contains the author
if ( array_key_exists( 315, $Exif_array[0] ) )
{
$outputarray = add_to_field( $outputarray, 'author' , HTML_UTF8_UnEscape( $Exif_array[0][315]['Data'][0] ), "\n" );
}
}
/***************************/
// FINISHED RETRIEVING INFORMATION
// Perform final processing
// Check if any urgency information was found
if ( $outputarray["urgency"] == "" )
{
// No urgency information was found - set it to default (None)
$outputarray["urgency"] = "none";
}
// Check if any copyrightstatus information was found
if ( $outputarray["copyrightstatus"] == "" )
{
// No copyrightstatus information was found - set it to default (Unmarked)
$outputarray["copyrightstatus"] = "unmarked";
}
// Return the resulting Photoshop File Info Array
return $outputarray;
}
/******************************************************************************
* End of Function: get_photoshop_file_info
******************************************************************************/
/******************************************************************************
*
* Function: put_photoshop_file_info
*
* Description: Stores Photoshop 'File Info' metadata in the same way that Photoshop
* does. The 'File Info' metadata must be in an array similar to that
* returned by get_photoshop_file_info, as follows:
*
* $file_info_array = array(
* "title" => "",
* "author" => "",
* "authorsposition" => "", // Note: Not used in Photoshop 7 or higher
* "caption" => "",
* "captionwriter" => "",
* "jobname" => "", // Note: Not used in Photoshop CS
* "copyrightstatus" => "",
* "copyrightnotice" => "",
* "ownerurl" => "",
* "keywords" => array( 0 => "", 1 => "", ... ),
* "category" => "", // Note: Max 3 characters
* "supplementalcategories" => array( 0 => "", 1 => "", ... ),
* "date" => "", // Note: DATE MUST BE IN YYYY-MM-DD format
* "city" => "",
* "state" => "",
* "country" => "",
* "credit" => "",
* "source" => "",
* "headline" => "",
* "instructions" => "",
* "transmissionreference" => "",
* "urgency" => "" );
*
* Parameters: jpeg_header_data - a JPEG header data array in the same format
* as from get_jpeg_header_data. This contains the
* header information which is to be updated.
* new_ps_file_info_array - An array as above, which contains the
* 'File Info' metadata information to be
* written.
* Old_Exif_array - an array containing the EXIF information to be
* updated, as retrieved by get_EXIF_JPEG. (saves having to parse the EXIF again)
* Old_XMP_array - an array containing the XMP information to be
* updated, as retrieved by read_XMP_array_from_text. (saves having to parse the XMP again)
* Old_IRB_array - an array containing the Photoshop IRB information
* to be updated, as retrieved by get_Photoshop_IRB. (saves having to parse the IRB again)
*
* Returns: jpeg_header_data - a JPEG header data array in the same format
* as from get_jpeg_header_data, containing the
* Photshop 'File Info' metadata. This can then
* be written to a file using put_jpeg_header_data.
*
******************************************************************************/
function put_photoshop_file_info( $jpeg_header_data, $new_ps_file_info_array, $Old_Exif_array, $Old_XMP_array, $Old_IRB_array )
{
/*******************************************/
// PREPROCESSING
// Check that the date is in the correct format (YYYY-MM-DD)
// Explode the date into pieces using the - symbol
$date_pieces = explode( "-", $new_ps_file_info_array[ 'date' ] );
// If there are not 3 pieces to the date, it is invalid
if ( count( $date_pieces ) != 3 )
{
// INVALID DATE
echo "Invalid Date - must be YYYY-MM-DD format<br>";
return FALSE;
}
// Cycle through each piece of the date
foreach( $date_pieces as $piece )
{
// If the piece is not numeric, then the date is invalid.
if ( ! is_numeric( $piece ) )
{
// INVALID DATE
echo "Invalid Date - must be YYYY-MM-DD format<br>";
return FALSE;
}
}
// Make a unix timestamp at midnight on the date specified
$date_stamp = mktime( 0,0,0, $date_pieces[1], $date_pieces[2], $date_pieces[0] );
// Create a translation table to remove carriage return characters
$trans = array( "\x0d" => "" );
// Cycle through each of the File Info elements
foreach( $new_ps_file_info_array as $valkey => $val )
{
// If the element is 'Keywords' or 'Supplemental Categories', then
// it is an array, and needs to be treated as one
if ( ( $valkey != 'supplementalcategories' ) && ( $valkey != 'keywords' ) )
{
// Not Keywords or Supplemental Categories
// Convert escaped HTML characters to UTF8 and remove carriage returns
$new_ps_file_info_array[ $valkey ] = strtr( HTML_UTF8_UnEscape( $val ), $trans );
}
else
{
// Either Keywords or Supplemental Categories
// Cycle through the array,
foreach( $val as $subvalkey => $subval )
{
// Convert escaped HTML characters to UTF8 and remove carriage returns
$new_ps_file_info_array[ $valkey ][ $subvalkey ] = strtr( HTML_UTF8_UnEscape( $subval ), $trans );
}
}
}
/*******************************************/
// EXIF Processing
// Check if the EXIF array exists
if( $Old_Exif_array == FALSE )
{
// EXIF Array doesn't exist - create a new one
$new_Exif_array = array ( 'Byte_Align' => "MM",
'Makernote_Tag' => false,
'Tags Name' => "TIFF",
0 => array( "Tags Name" => "TIFF" ) );
}
else
{
// EXIF Array Does Exist - use it
$new_Exif_array = $Old_Exif_array;
}
// Update the EXIF Image Description Tag with the new value
$new_Exif_array[0][270] = array ( "Tag Name" => $GLOBALS[ "IFD_Tag_Definitions" ]['TIFF'][ 270 ]['Name'],
"Tag Number" => 270,
"Data Type" => 2,
"Type" => $GLOBALS[ "IFD_Tag_Definitions" ]['TIFF'][ 270 ]['Type'],
"Data" => array( HTML_UTF8_Escape( $new_ps_file_info_array[ 'caption' ]) ));
// Update the EXIF Artist Name Tag with the new value
$new_Exif_array[0][315] = array ( "Tag Name" => $GLOBALS[ "IFD_Tag_Definitions" ]['TIFF'][ 315 ]['Name'],
"Tag Number" => 315,
"Data Type" => 2,
"Type" => $GLOBALS[ "IFD_Tag_Definitions" ]['TIFF'][ 315 ]['Type'],