/** * Draw the character's image onto a PDF page, within the given coordinates * * @param \SimplePdf\Page $page page to draw on * @param float $x1 x-coordinate of the top-left corner of the box to draw the image in * @param float $y1 y-coordinate of the top-left corner of the box to draw the image in * @param float $x2 x-coordinate of the bottom-right corner of the box to draw the image in * @param float $y2 y-coordinate of the bottom-right corner of the box to draw the image in * @param int $dpi DPI to use to render the image */ public function drawToPage(\SimplePdf\Page $page, $x1, $y1, $x2, $y2, $dpi) { $conversion = $dpi / 72; $page->convertToPoints($conversion); $width = $x2 - $x1; $height = $y2 - $y1; $imageWidth = $width * $conversion; $imageHeight = $height * $conversion; $tempFile = $this->prepareTemporaryImageFile($imageWidth, $imageHeight); list($newImageWidth, $newImageHeight) = getimagesize($tempFile); $imageResource = \ZendPdf\Image::imageWithPath($tempFile); unlink($tempFile); list($horizontalGravity, $verticalGravity) = $this->getGravityCoordinates(); if ($newImageHeight / $newImageWidth < $imageHeight / $imageWidth) { $remainder = $height - $width * ($newImageHeight / $newImageWidth); $y1 += $verticalGravity * $remainder; $y2 -= (1 - $verticalGravity) * $remainder; } else { $remainder = $width - $height / ($newImageHeight / $newImageWidth); $x1 += $horizontalGravity * $remainder; $x2 -= (1 - $horizontalGravity) * $remainder; } $page->drawImage($imageResource, $x1, $y1, $x2, $y2); }