Add function getListOfPossibleImageExt

This commit is contained in:
Laurent Destailleur 2021-04-08 14:20:59 +02:00
parent 638a4a6194
commit f8b5bee9eb
2 changed files with 25 additions and 7 deletions

View File

@ -30,6 +30,23 @@ $maxheightmini = 72; // 16/9eme
$quality = 80;
/**
* Return if a filename is file name of a supported image format
*
* @param int $acceptsvg 0=Default (depends on setup), 1=Always accept SVG as image files
* @return string Return list fo image format
*/
function getListOfPossibleImageExt($acceptsvg = 0)
{
global $conf;
$regeximgext = '\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.webp|\.xpm|\.xbm'; // See also into product.class.php
if ($acceptsvg || !empty($conf->global->MAIN_ALLOW_SVG_FILES_AS_IMAGES)) {
$regeximgext .= '|\.svg'; // Not allowed by default. SVG can contains javascript
}
return $regeximgext;
}
/**
* Return if a filename is file name of a supported image format
@ -40,12 +57,7 @@ $quality = 80;
*/
function image_format_supported($file, $acceptsvg = 0)
{
global $conf;
$regeximgext = '\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.webp|\.xpm|\.xbm'; // See also into product.class.php
if ($acceptsvg || !empty($conf->global->MAIN_ALLOW_SVG_FILES_AS_IMAGES)) {
$regeximgext .= '|\.svg'; // Not allowed by default. SVG can contains javascript
}
$regeximgext = getListOfPossibleImageExt();
// Case filename is not a format image
$reg = array();

View File

@ -2230,10 +2230,16 @@ if ($action == 'generatesitemaps' && $usercanedit) {
}
$action = 'preview';
}
$imagefolder = $conf->website->dir_output.'/'.$websitekey.'/medias/image/'.$websitekey.'/';
if ($action == 'convertimgwebp' && $usercanedit) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
$filelist = dol_dir_list($imagefolder, "all", 1);
$regeximgext = getListOfPossibleImageExt();
$filelist = dol_dir_list($imagefolder, "all", 1, $regeximgext);
foreach ($filelist as $filename) {
$filepath = $filename['fullname'];
if (!(substr_compare($filepath, 'webp', -strlen('webp')) === 0)) {