MSIN-4471 — Improve image handling in PDF generation by enforcing correct image type detection and ensuring proper width calculations. Update image insertion logic to accommodate various image formats and enhance layout consistency. Increment version code.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 92 KiB |
@ -9618,22 +9618,34 @@ function fxBibDistPrintWriteImage($pdf, $strPath, $fltMaxWMm = 0, $blnCenter = f
|
||||
$fltPageMax = $pdf->GetPageWidth() - $fltLeft - $fltRight;
|
||||
$fltMaxW = ($fltMaxWMm > 0) ? min($fltMaxWMm, $fltPageMax) : $fltPageMax;
|
||||
$tabSize = @getimagesize($strPath);
|
||||
if (!is_array($tabSize) || empty($tabSize[0]) || empty($tabSize[1])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// FPDF se fie à l'extension : forcer le type réel (ex. JPEG nommé .png).
|
||||
$strType = '';
|
||||
$strMime = isset($tabSize['mime']) ? strtolower((string)$tabSize['mime']) : '';
|
||||
if ($strMime === 'image/jpeg' || $strMime === 'image/jpg') {
|
||||
$strType = 'JPG';
|
||||
} elseif ($strMime === 'image/png') {
|
||||
$strType = 'PNG';
|
||||
} elseif ($strMime === 'image/gif') {
|
||||
$strType = 'GIF';
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
$fltW = $fltMaxW;
|
||||
if (is_array($tabSize) && !empty($tabSize[0]) && !empty($tabSize[1])) {
|
||||
$fltNatW = ($tabSize[0] * 25.4) / 96;
|
||||
if ($fltNatW > 0 && $fltNatW < $fltMaxW) {
|
||||
$fltW = $fltNatW;
|
||||
}
|
||||
}
|
||||
$fltH = 0;
|
||||
if (is_array($tabSize) && !empty($tabSize[0]) && !empty($tabSize[1])) {
|
||||
$fltH = $fltW * ($tabSize[1] / $tabSize[0]);
|
||||
$fltNatW = ($tabSize[0] * 25.4) / 96;
|
||||
if ($fltNatW > 0 && $fltNatW < $fltMaxW) {
|
||||
$fltW = $fltNatW;
|
||||
}
|
||||
$fltH = $fltW * ($tabSize[1] / $tabSize[0]);
|
||||
if ($pdf->GetY() + max(10, $fltH) > $pdf->GetPageHeight() - $fltBottom) {
|
||||
$pdf->AddPage();
|
||||
}
|
||||
$fltX = $blnCenter ? (($pdf->GetPageWidth() - $fltW) / 2) : $pdf->GetX();
|
||||
$pdf->Image($strPath, $fltX, $pdf->GetY(), $fltW);
|
||||
$pdf->Image($strPath, $fltX, $pdf->GetY(), $fltW, 0, $strType);
|
||||
$pdf->Ln(max(8, $fltH + 3));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user