douluhaikao93943 2016-01-18 07:17
浏览 418
已采纳

TCPDF添加由Php呈现的图像

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

  • 写回答

1条回答 默认 最新

  • dsfs1233 2016-01-18 07:53
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!