From 970f75d5e2a4bc9dc096d30b6b778a91c134fae9 Mon Sep 17 00:00:00 2001 From: Guillaume Lajarige Date: Wed, 29 Jun 2016 14:05:24 +0000 Subject: [PATCH] PDF export : Exporting objects with AttributeImage value to default was crashing due to a "division by zero". Fixed. SVN:trunk[4267] --- core/pdfbulkexport.class.inc.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/core/pdfbulkexport.class.inc.php b/core/pdfbulkexport.class.inc.php index ba50e8cff..ee27317ac 100644 --- a/core/pdfbulkexport.class.inc.php +++ b/core/pdfbulkexport.class.inc.php @@ -204,23 +204,28 @@ EOF { // To limit the image size in the PDF output, we have to enforce the size as height/width because max-width/max-height have no effect // - list($iWidth, $iHeight) = utils::GetImageSize($value->GetData()); - $iMaxWidthPx = min(48, $oAttDef->Get('display_max_width')); - $iMaxHeightPx = min(48, $oAttDef->Get('display_max_height')); - - $fScale = min($iMaxWidthPx / $iWidth, $iMaxHeightPx / $iHeight); - $iNewWidth = $iWidth * $fScale; - $iNewHeight = $iHeight * $fScale; + $iDefaultMaxWidthPx = 48; + $iDefaultMaxHeightPx = 48; if ($value->IsEmpty()) { + $iNewWidth = $iDefaultMaxWidthPx; + $iNewHeight = $iDefaultMaxHeightPx; + $sUrl = $oAttDef->Get('default_image'); - $sRet = ''; } else { - $sUrl = 'data:'.$value->GetMimeType().';base64,'.base64_encode($value->GetData()); - $sRet = ''; + list($iWidth, $iHeight) = utils::GetImageSize($value->GetData()); + $iMaxWidthPx = min($iDefaultMaxWidthPx, $oAttDef->Get('display_max_width')); + $iMaxHeightPx = min($iDefaultMaxHeightPx, $oAttDef->Get('display_max_height')); + + $fScale = min($iMaxWidthPx / $iWidth, $iMaxHeightPx / $iHeight); + $iNewWidth = $iWidth * $fScale; + $iNewHeight = $iHeight * $fScale; + + $sUrl = 'data:' . $value->GetMimeType() . ';base64,' . base64_encode($value->GetData()); } + $sRet = ''; $sRet = '
'.$sRet.'
'; } else