Skip to content

Commit

Permalink
fix issue on page background image width - issue #394
Browse files Browse the repository at this point in the history
  • Loading branch information
spipu committed Oct 26, 2018
1 parent 15ce89d commit 4fbcaad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.

* add `cert` tag - thanks to @LittleBigFox
* change the name of all the examples from `exemple` to `example`
* fix issue on page background image width - issue #394
* fix issue on qrcode value with multi lines - issue #390
* fix documentation - thanks to @noxlux and @tpohchai

Expand Down
21 changes: 13 additions & 8 deletions src/Html2Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,14 @@ protected function _setNewPage($format = null, $orientation = '', $background =
$this->pdf->Rect(0, 0, $this->pdf->getW(), $this->pdf->getH(), 'F');
}

if (isset($this->_background['img']) && $this->_background['img']) {
$this->pdf->Image($this->_background['img'], $this->_background['posX'], $this->_background['posY'], $this->_background['width']);
if (isset($this->_background['img']) && is_array($this->_background['img'])) {
$imageWidth = $this->cssConverter->convertToMM($this->_background['width'], $this->pdf->getW());
$imageHeight = $imageWidth * $this->_background['img']['height'] / $this->_background['img']['width'];

$posX = $this->cssConverter->convertToMM($this->_background['posX'], $this->pdf->getW() - $imageWidth);
$posY = $this->cssConverter->convertToMM($this->_background['posY'], $this->pdf->getH() - $imageHeight);

$this->pdf->Image($this->_background['img']['file'], $posX, $posY, $imageWidth);
}
}

Expand Down Expand Up @@ -2648,12 +2654,11 @@ protected function _tag_open_PAGE($param)
// WARNING : if URL, "allow_url_fopen" must turned to "on" in php.ini
$infos=@getimagesize($background['img']);
if (is_array($infos) && count($infos)>1) {
$imageWidth = $this->cssConverter->convertToMM($background['width'], $this->pdf->getW());
$imageHeight = $imageWidth*$infos[1]/$infos[0];

$background['width'] = $imageWidth;
$background['posX'] = $this->cssConverter->convertToMM($background['posX'], $this->pdf->getW() - $imageWidth);
$background['posY'] = $this->cssConverter->convertToMM($background['posY'], $this->pdf->getH() - $imageHeight);
$background['img'] = [
'file' => $background['img'],
'width' => (int) $infos[0],
'height' => (int) $infos[1]
];
} else {
$background = array();
}
Expand Down

0 comments on commit 4fbcaad

Please sign in to comment.