From 407cabcbe9d55abe60ab096f3740cd269dd5276e Mon Sep 17 00:00:00 2001 From: plegall Date: Mon, 21 Aug 2023 19:00:01 +0200 Subject: [PATCH] fixes #1966 support for EPS files (copied from Piwigo.com) --- admin/include/functions_upload.inc.php | 49 ++++++++++++++++++++++++++ include/config_default.inc.php | 3 ++ 2 files changed, 52 insertions(+) diff --git a/admin/include/functions_upload.inc.php b/admin/include/functions_upload.inc.php index 5ccb87b52..47d7a54ed 100644 --- a/admin/include/functions_upload.inc.php +++ b/admin/include/functions_upload.inc.php @@ -795,6 +795,55 @@ function upload_file_psd($representative_ext, $file_path) return get_extension($representative_file_abspath); } +add_event_handler('upload_file', 'upload_file_eps'); +function upload_file_eps($representative_ext, $file_path) +{ + global $logger, $conf; + + $logger->info(__FUNCTION__.', $file_path = '.$file_path.', $representative_ext = '.$representative_ext); + + if (isset($representative_ext)) + { + return $representative_ext; + } + + if (pwg_image::get_library() != 'ext_imagick') + { + return $representative_ext; + } + + if (!in_array(strtolower(get_extension($file_path)), array('eps'))) + { + return $representative_ext; + } + + // if the representative is "jpg", the derivatives are ugly. With "png" it's fine. + $ext = 'png'; + + // move the uploaded file to pwg_representative sub-directory + $representative_file_path = original_to_representative($file_path, $ext); + prepare_directory(dirname($representative_file_path)); + + // convert -density 300 image.eps -resize 2048x2048 image.png + + $exec = $conf['ext_imagick_dir'].'convert'; + $exec.= ' -density 300'; + $exec.= ' "'.realpath($file_path).'"'; + $exec.= ' -resize 2048x2048'; + $exec.= ' "'.$representative_file_path.'"'; + $exec.= ' 2>&1'; + $logger->info(__FUNCTION__.', $exec = '.$exec); + @exec($exec, $returnarray); + + // Return the extension (if successful) or false (if failed) + if (file_exists($representative_file_path)) + { + $representative_ext = $ext; + } + + return $representative_ext; +} + function prepare_directory($directory) { if (!is_dir($directory)) { diff --git a/include/config_default.inc.php b/include/config_default.inc.php index c573536a3..bfeec0de4 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -43,6 +43,9 @@ $conf['picture_ext'] = array('jpg','jpeg','png','gif'); // file_ext : file extensions (case sensitive) authorized +// +// * if you enable "eps" file extension, make sure you have this file type +// authorized in your ImageMagick policy $conf['file_ext'] = array_merge( $conf['picture_ext'], array('tiff', 'tif', 'mpg','zip','avi','mp3','ogg','pdf','svg', 'heic')