Why is there not a Offset for MemoryDrawing but Drawing when Html::writeImageInCell? #3529
Closed
Description
This is a part of source code of Html::writeImageInCell.
Class MemoryDrawing has offsets attributtes also, and I dont understand why not sets 'top','left' for the 'img' Tag.
if ($drawing instanceof Drawing) {
$filename = $drawing->getPath();
// Strip off eventual '.'
$filename = (string) preg_replace('/^[.]/', '', $filename);
// Prepend images root
$filename = $this->getImagesRoot() . $filename;
// Strip off eventual '.' if followed by non-/
$filename = (string) preg_replace('@^[.]([^/])@', '$1', $filename);
// Convert UTF8 data to PCDATA
$filename = htmlspecialchars($filename, Settings::htmlEntityFlags());
$html .= PHP_EOL;
$imageData = self::winFileToUrl($filename, $this->isMPdf);
if ($this->embedImages || substr($imageData, 0, 6) === 'zip://') {
$picture = @file_get_contents($filename);
if ($picture !== false) {
$imageDetails = getimagesize($filename) ?: [];
// base64 encode the binary data
$base64 = base64_encode($picture);
$imageData = 'data:' . $imageDetails['mime'] . ';base64,' . $base64;
}
}
$html .= '<img style="position: absolute; z-index: 1; left: ' .
/**** give Offset ****/
$drawing->getOffsetX() . 'px; top: ' . $drawing->getOffsetY() . 'px; width: ' .
$drawing->getWidth() . 'px; height: ' . $drawing->getHeight() . 'px;" src="' .
$imageData . '" alt="' . $filedesc . '" />';
} elseif ($drawing instanceof MemoryDrawing) {
$imageResource = $drawing->getImageResource();
if ($imageResource) {
ob_start(); // Let's start output buffering.
imagepng($imageResource); // This will normally output the image, but because of ob_start(), it won't.
$contents = (string) ob_get_contents(); // Instead, output above is saved to $contents
ob_end_clean(); // End the output buffer.
$dataUri = 'data:image/png;base64,' . base64_encode($contents);
// Because of the nature of tables, width is more important than height.
// max-width: 100% ensures that image doesnt overflow containing cell
// width: X sets width of supplied image.
// As a result, images bigger than cell will be contained and images smaller will not get stretched
$html .= '<img alt="' . $filedesc . '" src="' . $dataUri . '" style="max-width:100%;width:' . $drawing->getWidth() . 'px;" />';
}
}
Metadata
Assignees
Labels
No labels