@@ -39,6 +39,11 @@ class Exiftool extends AdapterAbstract
39
39
*/
40
40
protected $ numeric = true ;
41
41
42
+ /**
43
+ * @var array
44
+ */
45
+ protected $ encoding = array ();
46
+
42
47
/**
43
48
* @var string
44
49
*/
@@ -75,6 +80,26 @@ public function setNumeric($numeric)
75
80
$ this ->numeric = $ numeric ;
76
81
}
77
82
83
+ /**
84
+ * @see http://www.sno.phy.queensu.ca/~phil/exiftool/faq.html#Q10
85
+ * @param array $encoding encoding parameters in an array eg. ["exif" => "UTF-8"]
86
+ */
87
+ public function setEncoding ($ encoding )
88
+ {
89
+ $ possible_keys = array ("exif " , "iptc " , "id3 " , "photoshop " , "quicktime " ,);
90
+ $ possible_values = array ("UTF8 " , "cp65001 " , "UTF-8 " , "Thai " , "cp874 " , "Latin " , "cp1252 " ,
91
+ "Latin1 " , "MacRoman " , "cp10000 " , "Mac " , "Roman " , "Latin2 " , "cp1250 " , "MacLatin2 " ,
92
+ "cp10029 " , "Cyrillic " , "cp1251 " , "Russian " , "MacCyrillic " , "cp10007 " , "Greek " ,
93
+ "cp1253 " , "MacGreek " , "cp10006 " , "Turkish " , "cp1254 " , "MacTurkish " , "cp10081 " ,
94
+ "Hebrew " , "cp1255 " , "MacRomanian " , "cp10010 " , "Arabic " , "cp1256 " , "MacIceland " ,
95
+ "cp10079 " , "Baltic " , "cp1257 " , "MacCroatian " , "cp10082 " , "Vietnam " , "cp1258 " ,);
96
+ foreach ($ encoding as $ type => $ encoding ) {
97
+ if (in_array ($ type , $ possible_keys ) && in_array ($ encoding , $ possible_values )) {
98
+ $ this ->encoding [$ type ] = $ encoding ;
99
+ }
100
+ }
101
+ }
102
+
78
103
/**
79
104
* Getter for the exiftool binary path
80
105
* Lazy loads the "default" path
@@ -100,17 +125,33 @@ public function getToolPath()
100
125
*/
101
126
public function getExifFromFile ($ file )
102
127
{
128
+ $ encoding = '' ;
129
+ if (!empty ($ this ->encoding )) {
130
+ $ encoding = '-charset ' ;
131
+ foreach ($ this ->encoding as $ key => $ value ) {
132
+ $ encoding .= escapeshellarg ($ key ).'= ' .escapeshellarg ($ value );
133
+ }
134
+ }
103
135
$ result = $ this ->getCliOutput (
104
136
sprintf (
105
- '%1$s%3$s -j -a -G1 -c %4$s %2$s ' ,
137
+ '%1$s%3$s -j -a -G1 %5$s -c %4$s %2$s ' ,
106
138
$ this ->getToolPath (),
107
139
escapeshellarg ($ file ),
108
140
$ this ->numeric ? ' -n ' : '' ,
109
- escapeshellarg ('%d deg %d \' %.4f" ' )
141
+ escapeshellarg ('%d deg %d \' %.4f" ' ),
142
+ $ encoding
110
143
)
111
144
);
112
145
113
- $ data = json_decode (utf8_encode ($ result ), true );
146
+ if (!mb_check_encoding ($ result , "utf-8 " )) {
147
+ $ result = utf8_encode ($ result );
148
+ }
149
+ $ data = json_decode ($ result , true );
150
+ if (!is_array ($ data )) {
151
+ throw new RuntimeException (
152
+ 'Could not decode exiftool output '
153
+ );
154
+ }
114
155
115
156
// map the data:
116
157
$ mapper = $ this ->getMapper ();
0 commit comments