Fix pb with imagick

This commit is contained in:
Laurent Destailleur 2017-08-29 13:41:44 +02:00
parent 22ca29a51f
commit eebaff95cf
2 changed files with 24 additions and 14 deletions

View File

@ -1565,34 +1565,41 @@ function dol_remove_file_process($filenb,$donotupdatesession=0,$donotdeletefile=
* @param string $fileinput Input file name * @param string $fileinput Input file name
* @param string $ext Format of target file (It is also extension added to file if fileoutput is not provided). * @param string $ext Format of target file (It is also extension added to file if fileoutput is not provided).
* @param string $fileoutput Output filename * @param string $fileoutput Output filename
* @return int <0 if KO, >0 if OK * @return int <0 if KO, 0=Nothing done, >0 if OK
*/ */
function dol_convert_file($fileinput,$ext='png',$fileoutput='') function dol_convert_file($fileinput,$ext='png',$fileoutput='')
{ {
global $langs; global $langs;
$image=new Imagick(); if (class_exists('Imagick'))
$ret = $image->readImage($fileinput);
if ($ret)
{ {
$ret = $image->setImageFormat($ext); $image=new Imagick();
$ret = $image->readImage($fileinput);
if ($ret) if ($ret)
{ {
if (empty($fileoutput)) $fileoutput=$fileinput.".".$ext; $ret = $image->setImageFormat($ext);
if ($ret)
{
if (empty($fileoutput)) $fileoutput=$fileinput.".".$ext;
$count = $image->getNumberImages(); $count = $image->getNumberImages();
$ret = $image->writeImages($fileoutput, true); $ret = $image->writeImages($fileoutput, true);
if ($ret) return $count; if ($ret) return $count;
else return -3; else return -3;
}
else
{
return -2;
}
} }
else else
{ {
return -2; return -1;
} }
} }
else else
{ {
return -1; return 0;
} }
} }

View File

@ -1236,8 +1236,11 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r
&& (! file_exists($fileimagebis) || (filemtime($fileimagebis) < filemtime($file))) && (! file_exists($fileimagebis) || (filemtime($fileimagebis) < filemtime($file)))
) )
{ {
$ret = dol_convert_file($file, 'png', $fileimage); if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) // If you experienc trouble with pdf thumb generation and imagick, you can disable here.
if ($ret < 0) $error++; {
$ret = dol_convert_file($file, 'png', $fileimage);
if ($ret < 0) $error++;
}
} }
$heightforphotref=70; $heightforphotref=70;