@@ -116,6 +116,30 @@ protected function get_file_objects() {
116116 protected function create_scaled_image ($ file_name , $ options ) {
117117 $ file_path = $ this ->options ['upload_dir ' ].$ file_name ;
118118 $ new_file_path = $ options ['upload_dir ' ].$ file_name ;
119+
120+ if (extension_loaded ('imagick ' )) {
121+ // Special PSD & AI case
122+ $ file_ext = strtolower (substr (strrchr ($ file_name , '. ' ), 1 ));
123+ switch ($ file_ext ) {
124+ case 'ai ' :
125+ case 'psd ' :
126+ case 'pdf ' :
127+ try {
128+ $ im = new \Imagick ($ file_path );
129+ $ im ->flattenImages ();
130+ $ im ->setImageFormat ('png ' );
131+ $ file_name .= '.png ' ;
132+ $ file_path .= '.png ' ;
133+ $ new_file_path .= '.png ' ;
134+ $ im ->writeImage ($ file_path );
135+ } catch (\ImagickException $ e ) {
136+ return false ;
137+ }
138+ break ;
139+
140+ }
141+ }
142+
119143 list ($ img_width , $ img_height ) = @getimagesize ($ file_path );
120144 if (!$ img_width || !$ img_height ) {
121145 return false ;
@@ -329,10 +353,15 @@ protected function handle_file_upload($uploaded_file, $name, $size, $type, $erro
329353 }
330354 $ file ->url = $ this ->options ['upload_url ' ].rawurlencode ($ file ->name );
331355 foreach ($ this ->options ['image_versions ' ] as $ version => $ options ) {
356+ $ thumbnail_ext = '' ;
332357 if ($ this ->create_scaled_image ($ file ->name , $ options )) {
333358 if ($ this ->options ['upload_dir ' ] !== $ options ['upload_dir ' ]) {
334- $ file ->{$ version .'_url ' } = $ options ['upload_url ' ]
335- .rawurlencode ($ file ->name );
359+ $ file_ext = strtolower (substr (strrchr ($ file ->name , '. ' ), 1 ));
360+ if ($ file_ext == 'ai ' || $ file_ext == 'psd ' || $ file_ext == 'png ' ) {
361+ $ thumbnail_ext = '.png ' ;
362+ }
363+
364+ $ file ->{$ version .'_url ' } = $ options ['upload_url ' ].rawurlencode ($ file ->name ).$ thumbnail_ext ;
336365 } else {
337366 clearstatcache ();
338367 $ file_size = filesize ($ file_path );
@@ -435,4 +464,4 @@ public function delete() {
435464 echo json_encode ($ success );
436465 }
437466
438- }
467+ }
0 commit comments