@@ -39,6 +39,11 @@ class Exiftool extends AdapterAbstract
3939 */
4040 protected $ numeric = true ;
4141
42+ /**
43+ * @var array
44+ */
45+ protected $ encoding = array ();
46+
4247 /**
4348 * @var string
4449 */
@@ -75,6 +80,26 @@ public function setNumeric($numeric)
7580 $ this ->numeric = $ numeric ;
7681 }
7782
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+
78103 /**
79104 * Getter for the exiftool binary path
80105 * Lazy loads the "default" path
@@ -100,17 +125,33 @@ public function getToolPath()
100125 */
101126 public function getExifFromFile ($ file )
102127 {
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+ }
103135 $ result = $ this ->getCliOutput (
104136 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 ' ,
106138 $ this ->getToolPath (),
107139 escapeshellarg ($ file ),
108140 $ this ->numeric ? ' -n ' : '' ,
109- escapeshellarg ('%d deg %d \' %.4f" ' )
141+ escapeshellarg ('%d deg %d \' %.4f" ' ),
142+ $ encoding
110143 )
111144 );
112145
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+ }
114155
115156 // map the data:
116157 $ mapper = $ this ->getMapper ();
0 commit comments