🌍
English
On Piwigo.com we have added support for a few file types, such as EPS, PSD (Adobe Photoshop), AI (Adobe Illustrator. The idea is not to keep it for Piwigo.com. I think I will create a plugin to provide this support on all Piwigo. For now, here are some piece of code you can use in a Personal plugin:
add_event_handler('upload_file', 'upload_file_psd'); function upload_file_psd($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('psd'))) { return $representative_ext; } // move the uploaded file to pwg_representative sub-directory $representative_file_path = dirname($file_path).'/pwg_representative/'; $representative_file_path.= get_filename_wo_extension(basename($file_path)).'.'; $representative_ext = 'png'; $representative_file_path.= $representative_ext; prepare_directory(dirname($representative_file_path)); $exec = $conf['ext_imagick_dir'].'convert'; $exec .= ' "'.realpath($file_path).'"'; $dest = pathinfo($representative_file_path); $exec .= ' "'.realpath($dest['dirname']).'/'.$dest['basename'].'"'; $exec .= ' 2>&1'; $logger->info(__FUNCTION__.', exec = '.$exec); @exec($exec, $returnarray); // sometimes ImageMagick creates file-0.png + file-1.png + file-2.png... // It seems we can't avoid it. $representative_file_abspath = realpath($dest['dirname']).'/'.$dest['basename']; if (!file_exists($representative_file_abspath)) { $first_file_abspath = preg_replace( '/\.'.$representative_ext.'$/', '-0.'.$representative_ext, $representative_file_abspath ); if (file_exists($first_file_abspath)) { rename($first_file_abspath, $representative_file_abspath); } } return get_extension($representative_file_abspath); }
RAW files, based on JPEG extraction with exiftool.
add_event_handler('upload_file', 'pcom_upload_file_raw'); function pcom_upload_file_raw($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; } // TODO check exiftool is available if (!in_array(strtolower(get_extension($file_path)), array('arw'))) { return $representative_ext; } // move the uploaded file to pwg_representative sub-directory $representative_file_path = dirname($file_path).'/pwg_representative/'; $representative_file_path.= get_filename_wo_extension(basename($file_path)).'.jpg'; prepare_directory(dirname($representative_file_path)); $exec = isset($conf['exiftool_path']) ? $conf['exiftool_path'] : 'exiftool'; $exec.= ' -b -previewImage'; $exec.= ' "'.realpath($file_path).'"'; $dest = pathinfo($representative_file_path); $representative_file_abspath = realpath($dest['dirname']).'/'.$dest['basename']; $exec .= ' > "'.$representative_file_abspath.'"'; $exec .= ' 2>&1'; $logger->info(__FUNCTION__.', exec = '.$exec); @exec($exec, $returnarray); // let's check the extracted file list($width, $height, $type) = getimagesize($representative_file_abspath); if (IMAGETYPE_JPEG !== $type) { return $representative_ext; } return get_extension($representative_file_abspath); }
better support for PDF files with pdftoppm command line tool
add_event_handler('upload_file', 'pcom_upload_file_pdf'); function pcom_upload_file_pdf($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 (!isset($conf['use_pdftoppm']) or !$conf['use_pdftoppm']) { return $representative_ext; } if (!in_array(strtolower(get_extension($file_path)), array('pdf'))) { return $representative_ext; } $ext = conf_get_param('pdf_representative_ext', 'jpg'); // move the uploaded file to pwg_representative sub-directory $representative_file_path = original_to_representative($file_path, $ext); prepare_directory(dirname($representative_file_path)); $representative_file_path_wo_ext = get_filename_wo_extension($representative_file_path); $exec = 'pdftoppm'; $exec.= ' "'.realpath($file_path).'"'; $exec.= ' "'.$representative_file_path_wo_ext.'"'; if ('jpg' == $ext) { $exec.= ' -jpeg'; } else { $exec.= ' -png'; } $exec.= ' -f 1 -singlefile'; $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; }
Support for AI, based on the use of "gs" command line
add_event_handler('upload_file', 'pcom_upload_file_ai'); function pcom_upload_file_ai($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 (!in_array(strtolower(get_extension($file_path)), array('ai'))) { return $representative_ext; } $ext = 'png'; $representative_file_path = original_to_representative($file_path, $ext); prepare_directory(dirname($representative_file_path)); // gs -dNOPAUSE -dBATCH -sDEVICE=pngalpha -r300 -sOutputFile=out.png in.ai $exec = 'gs -dNOPAUSE -dBATCH -sDEVICE=pngalpha -r300 -sOutputFile='; $exec.= '"'.realpath($representative_file_path).'"'; $exec.= ' "'.realpath($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; }
EPS files
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'; @exec($exec, $returnarray); // Return the extension (if successful) or false (if failed) if (file_exists($representative_file_path)) { $representative_ext = $ext; } return $representative_ext; }
Offline
This is great! Thanks so much.
Any plans to include tif?
Offline
See also [Forum, topic 31223] My solution to implement new image types for example ico, svg and webp.
Offline