NEW Mutualize code: Use one call of function "addThumbs", when possible,
to generate thumbs files instead of several call of "vignette" function.
This commit is contained in:
parent
e869ed51e4
commit
5b55af4d66
@ -356,13 +356,8 @@ if (empty($reshook))
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create small thumbs for company (Ratio is near 16/9)
|
||||
// Used on logon for example
|
||||
$imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
|
||||
|
||||
// Create mini thumbs for company (Ratio is near 16/9)
|
||||
// Used on menu or for setup page for example
|
||||
$imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
|
||||
// Create thumbs
|
||||
$object->addThumbs($newfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,12 +98,14 @@ if ( ($action == 'update' && empty($_POST["cancel"]))
|
||||
// Create thumbs of logo (Note that PDF use original file and not thumbs)
|
||||
if ($isimage > 0)
|
||||
{
|
||||
// Create small thumbs for company (Ratio is near 16/9)
|
||||
// Create thumbs
|
||||
//$object->addThumbs($newfile); // We can't use addThumbs here yet because we need name of generated thumbs to add them into constants. TODO Check if need such constants. We should be able to retreive value with get...
|
||||
|
||||
// Used on logon for example
|
||||
$imgThumbSmall = vignette($conf->mycompany->dir_output.'/logos/'.$original_file, $maxwidthsmall, $maxheightsmall, '_small', $quality);
|
||||
if (preg_match('/([^\\/:]+)$/i',$imgThumbSmall,$reg))
|
||||
if (image_format_supported($imgThumbSmall) >= 0 && preg_match('/([^\\/:]+)$/i',$imgThumbSmall,$reg))
|
||||
{
|
||||
$imgThumbSmall = $reg[1];
|
||||
$imgThumbSmall = $reg[1]; // Save only basename
|
||||
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL",$imgThumbSmall,'chaine',0,'',$conf->entity);
|
||||
}
|
||||
else dol_syslog($imgThumbSmall);
|
||||
@ -111,9 +113,9 @@ if ( ($action == 'update' && empty($_POST["cancel"]))
|
||||
// Create mini thumbs for company (Ratio is near 16/9)
|
||||
// Used on menu or for setup page for example
|
||||
$imgThumbMini = vignette($conf->mycompany->dir_output.'/logos/'.$original_file, $maxwidthmini, $maxheightmini, '_mini', $quality);
|
||||
if (preg_match('/([^\\/:]+)$/i',$imgThumbMini,$reg))
|
||||
if (image_format_supported($imgThumbMini) >= 0 && preg_match('/([^\\/:]+)$/i',$imgThumbMini,$reg))
|
||||
{
|
||||
$imgThumbMini = $reg[1];
|
||||
$imgThumbMini = $reg[1]; // Save only basename
|
||||
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI",$imgThumbMini,'chaine',0,'',$conf->entity);
|
||||
}
|
||||
else dol_syslog($imgThumbMini);
|
||||
@ -203,12 +205,14 @@ if ($action == 'addthumb')
|
||||
// Create thumbs of logo
|
||||
if ($isimage > 0)
|
||||
{
|
||||
// Create small thumbs for company (Ratio is near 16/9)
|
||||
// Create thumbs
|
||||
//$object->addThumbs($newfile); // We can't use addThumbs here yet because we need name of generated thumbs to add them into constants. TODO Check if need such constants. We should be able to retreive value with get...
|
||||
|
||||
// Used on logon for example
|
||||
$imgThumbSmall = vignette($conf->mycompany->dir_output.'/logos/'.$_GET["file"], $maxwidthsmall, $maxheightsmall, '_small',$quality);
|
||||
if (image_format_supported($imgThumbSmall) >= 0 && preg_match('/([^\\/:]+)$/i',$imgThumbSmall,$reg))
|
||||
{
|
||||
$imgThumbSmall = $reg[1];
|
||||
$imgThumbSmall = $reg[1]; // Save only basename
|
||||
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_SMALL",$imgThumbSmall,'chaine',0,'',$conf->entity);
|
||||
}
|
||||
else dol_syslog($imgThumbSmall);
|
||||
@ -218,7 +222,7 @@ if ($action == 'addthumb')
|
||||
$imgThumbMini = vignette($conf->mycompany->dir_output.'/logos/'.$_GET["file"], $maxwidthmini, $maxheightmini, '_mini',$quality);
|
||||
if (image_format_supported($imgThumbSmall) >= 0 && preg_match('/([^\\/:]+)$/i',$imgThumbMini,$reg))
|
||||
{
|
||||
$imgThumbMini = $reg[1];
|
||||
$imgThumbMini = $reg[1]; // Save only basename
|
||||
dolibarr_set_const($db, "MAIN_INFO_SOCIETE_LOGO_MINI",$imgThumbMini,'chaine',0,'',$conf->entity);
|
||||
}
|
||||
else dol_syslog($imgThumbMini);
|
||||
|
||||
@ -1451,8 +1451,8 @@ class Categorie extends CommonObject
|
||||
|
||||
if (file_exists($originImage))
|
||||
{
|
||||
// Cree fichier en taille vignette
|
||||
$this->add_thumb($originImage);
|
||||
// Create thumbs
|
||||
$this->addThumbs($originImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ if ($action == 'confirm_delete' && $_GET["file"] && $confirm == 'yes' && $user->
|
||||
|
||||
if ($action == 'addthumb' && $_GET["file"])
|
||||
{
|
||||
$object->add_thumb($upload_dir."/".$_GET["file"]);
|
||||
$object->addThumbs($upload_dir."/".$_GET["file"]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -92,18 +92,10 @@ if ($_POST["sendit"] && !empty($conf->global->MAIN_UPLOAD_DOC)) {
|
||||
$upload_dir . "/" . dol_unescapefile($_FILES['userfile']['name']),
|
||||
0, 0, $_FILES['userfile']['error']);
|
||||
if (is_numeric($resupload) && $resupload > 0) {
|
||||
if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name'])
|
||||
== 1) {
|
||||
// Create small thumbs for image (Ratio is near 16/9)
|
||||
// Used on logon for example
|
||||
$imgThumbSmall = vignette($upload_dir . "/" . $_FILES['userfile']['name'],
|
||||
$maxwidthsmall, $maxheightsmall, '_small', $quality,
|
||||
"thumbs");
|
||||
// Create mini thumbs for image (Ratio is near 16/9)
|
||||
// Used on menu or for setup page for example
|
||||
$imgThumbMini = vignette($upload_dir . "/" . $_FILES['userfile']['name'],
|
||||
$maxwidthmini, $maxheightmini, '_mini', $quality,
|
||||
"thumbs");
|
||||
if (image_format_supported($upload_dir . "/" . $_FILES['userfile']['name']) == 1)
|
||||
{
|
||||
// Create thumbs
|
||||
$object->addThumbs($upload_dir . "/" . $_FILES['userfile']['name']);
|
||||
}
|
||||
$mesg = '<div class="ok">' . $langs->trans("FileTransferComplete") . '</div>';
|
||||
}
|
||||
|
||||
@ -314,13 +314,9 @@ if (empty($reshook))
|
||||
else
|
||||
{
|
||||
$object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
|
||||
// Create small thumbs for company (Ratio is near 16/9)
|
||||
// Used on logon for example
|
||||
$imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
|
||||
|
||||
// Create mini thumbs for company (Ratio is near 16/9)
|
||||
// Used on menu or for setup page for example
|
||||
$imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
|
||||
// Create thumbs
|
||||
$object->addThumbs($newfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,13 +87,8 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create small thumbs for company (Ratio is near 16/9)
|
||||
// Used on logon for example
|
||||
$imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
|
||||
|
||||
// Create mini thumbs for company (Ratio is near 16/9)
|
||||
// Used on menu or for setup page for example
|
||||
$imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
|
||||
// Create thumbs
|
||||
$object->addThumbs($newfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3910,7 +3910,7 @@ abstract class CommonObject
|
||||
* @param string $file Path file in UTF8 to original file to create thumbs from.
|
||||
* @return void
|
||||
*/
|
||||
function add_thumb($file)
|
||||
function addThumbs($file)
|
||||
{
|
||||
global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini, $quality;
|
||||
|
||||
|
||||
@ -257,7 +257,7 @@ class FileUpload
|
||||
}
|
||||
|
||||
/**
|
||||
* Create thumbs
|
||||
* Create thumbs of a file uploaded. Only the "mini" thumb is generated.
|
||||
*
|
||||
* @param string $file_name Filename
|
||||
* @param string $options is array('max_width', 'max_height')
|
||||
@ -277,9 +277,8 @@ class FileUpload
|
||||
return false;
|
||||
}
|
||||
|
||||
$res=vignette($file_path,$maxwidthmini,$maxheightmini,'_mini');
|
||||
$res=vignette($file_path,$maxwidthmini,$maxheightmini,'_mini'); // We don't use ->addThumbs here because there is no object and we don't need all thumbs, only the "mini".
|
||||
|
||||
//return $success;
|
||||
if (preg_match('/error/i',$res)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1486,7 +1486,9 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio
|
||||
}
|
||||
if (image_format_supported($destpath) == 1)
|
||||
{
|
||||
// Create small thumbs for image (Ratio is near 16/9)
|
||||
// Create thumbs
|
||||
// We can't use $object->addThumbs here because there is no $object known
|
||||
|
||||
// Used on logon for example
|
||||
$imgThumbSmall = vignette($destpath, $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs");
|
||||
// Create mini thumbs for image (Ratio is near 16/9)
|
||||
|
||||
@ -124,7 +124,7 @@ if ($action == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POS
|
||||
|
||||
if ($result == $fullpath)
|
||||
{
|
||||
$object->add_thumb($fullpath);
|
||||
$object->addThumbs($fullpath);
|
||||
|
||||
if ($backtourl)
|
||||
{
|
||||
@ -153,7 +153,7 @@ if ($action == 'confirm_crop')
|
||||
|
||||
if ($result == $fullpath)
|
||||
{
|
||||
$object->add_thumb($fullpath);
|
||||
$object->addThumbs($fullpath);
|
||||
|
||||
if ($backtourl)
|
||||
{
|
||||
|
||||
@ -3507,8 +3507,8 @@ class Product extends CommonObject
|
||||
|
||||
if (file_exists(dol_osencode($originImage)))
|
||||
{
|
||||
// Cree fichier en taille vignette
|
||||
$this->add_thumb($originImage);
|
||||
// Create thumbs
|
||||
$this->addThumbs($originImage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -481,13 +481,8 @@ if (empty($reshook))
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create small thumbs for company (Ratio is near 16/9)
|
||||
// Used on logon for example
|
||||
$imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
|
||||
|
||||
// Create mini thumbs for company (Ratio is near 16/9)
|
||||
// Used on menu or for setup page for example
|
||||
$imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
|
||||
// Create thumbs
|
||||
$object->addThumbs($newfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -859,13 +854,8 @@ else
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create small thumbs for company (Ratio is near 16/9)
|
||||
// Used on logon for example
|
||||
$imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
|
||||
|
||||
// Create mini thumbs for company (Ratio is near 16/9)
|
||||
// Used on menu or for setup page for example
|
||||
$imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
|
||||
// Create thumbs
|
||||
$object->addThumbs($newfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -453,13 +453,8 @@ if (empty($reshook)) {
|
||||
if (!$result > 0) {
|
||||
setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
|
||||
} else {
|
||||
// Create small thumbs for company (Ratio is near 16/9)
|
||||
// Used on logon for example
|
||||
$imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
|
||||
|
||||
// Create mini thumbs for company (Ratio is near 16/9)
|
||||
// Used on menu or for setup page for example
|
||||
$imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
|
||||
// Create thumbs
|
||||
$object->addThumbs($newfile);
|
||||
}
|
||||
} else {
|
||||
$error ++;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user