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!

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

报告相同问题?

悬赏问题

  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决