Reputation: 486
i am having issues to add image on pdf file using tcpdf. my image is rendered by php script.
below is the script call mode: (worked well when directly check on browser):
./Image.php?t=1049&e=100003&i=25040907060040
but when i try to add using tcpdf using below code:
$pdf->Image('./Image.php?t=1049&e=100003&i=25040907060040', '', '', 20, 20, 'jpg', '', 'T', false, 300, '', false, false, 0, false, false, false);
it fails with following errors:
Error 1:
Warning: getimagesize(./Image.php?t=1049&e=100003&i=25040907060040): failed to open stream: No error in .\Classes\tcpdf\include\tcpdf_images.php on line 171
Error 2:
Warning: imagecreatefromjpeg(./Image.php?t=1049&e=100003&i=25040907060040): failed to open stream: No error in .\Classes\tcpdf\tcpdf.php on line 7033
so, how can i add image using above php script (Image.php)?
thanks in advance
Upvotes: 1
Views: 791
Reputation: 1197
It fails because your code looks for a data stream for image data.
The best solution is to include Image.php
which will have a function to output image data.
Suppose the Image.php
have class ImageRenderer
with a public function called render_image()
;
The you can have the image rendered to the PDF like this..
require_once('Image.php');
$dynimage = ImageRenderer::render_image(1049,100003,25040907060040); // Parameters t=1049&e=100003&i=25040907060040
// $dynimage will have some data like 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABlBMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDrEX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg=='
$imgdata = base64_decode($dynimage); // decode stream
// The '@' character is used to indicate that follows an image data stream and not an image file name
$pdf->Image('@'.$imgdata);
Hope this helps!
Upvotes: 1