【问题标题】:FPDF error: Unsupported image type (while using header to define image)FPDF 错误:不支持的图像类型(使用标题定义图像时)
【发布时间】:2023-04-03 09:01:01
【问题描述】:

所以我有一个图像字符串,我将它插入到一个带有标题的网页中,告诉浏览器它是一个图像。

所以页面应该是这样的:

<?php
    header('Content-Type: image/png');
    echo $image_data;
?>

http://website.com/randomString.png用于抓取图片(使用.htaccess)

当我使用以下代码时,我收到错误FPDF error: Unsupported image type

$imagePath = file_get_contents("http://website.com/".$randomString.".png");
$pdf->Image($imagePath,159,185,27);

有谁知道我可以做些什么来摆脱这个错误?

【问题讨论】:

    标签: php fpdf pdftk


    【解决方案1】:

    用MemImage替换Image(并从下面的列表中复制类或自己复制函数),否则它想从文件中读取图像。

    http://www.fpdf.org/en/script/script45.php

    【讨论】:

    • 啊,好吧,让我把这个 MemImage 包含进来,看看它是否有效,谢谢!
    • 查看链接并从那里复制函数。
    • 我使用 $pdf = new FPDI(); 而不是 $pdf = new PDF_MemImage(); 就像它要求我那样,所以我只需要弄清楚如何将该功能合并到现有的 fpdf 页面中
    • 没关系,您可以将类 PDI 扩展为class PDF_MemImage extends FPDI 并以相同的方式运行所有内容。
    • 我将所有内容复制并粘贴到我的fpdf.php 页面底部,然后我得到一个Call to undefined method FPDI::MemImage()
    猜你喜欢
    • 1970-01-01
    • 2012-04-17
    • 1970-01-01
    • 1970-01-01
    • 2022-09-25
    • 1970-01-01
    • 2018-06-14
    • 2017-06-15
    • 2011-11-02
    相关资源
    最近更新 更多