TCPDF错误:无法获取图像的大小 [英] TCPDF error :Unable to get the size of the image

查看:2509
本文介绍了TCPDF错误:无法获取图像的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TCPDF来创建动态生成的pdf文件。在我的pdf文件中,根据用户输入生成图像,我想在我的pdf文件中添加该图像。这是我的代码

I am using TCPDF to create dynamically generated pdf file . In my pdf file a image is generated based on user input and I want to add that image on my pdf file . Here is my code

 $map_image = "example.com/wp-content/themes/example/map_image_leasing.php/?city=Calgary&suit_type=&min_area=&max_area=";

$pdf->Image ($map_image, 55, 19, '', '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);

如果我粘贴 example.com/wp-content/themes/example/map_image_leasing。 php /?city = Calgary& suit_type =& min_area =& max_area = 这在我的网址上创建了我想要的图像,但如果放入此网址,则无效。它说无法获得图片的大小

If i paste "example.com/wp-content/themes/example/map_image_leasing.php/?city=Calgary&suit_type=&min_area=&max_area=" this on my url this create image as I wanted , but If put this url , it doesn't work . It says Unable to get the size of the image

但如果我放了这样的东西

But if I put something like this

$map_image = '/wp-content/themes/v3/resources/images/public/logo_side.jpg';

它可以成功生成带有该图像的pdf。

It can generate pdf with that image successfully .

我该如何解决?

我访问了以下stackoverflow链接,但没有任何帮助

I have visited the following stackoverflow link , but none of this came to any help

tcpdf在localhost上工作但不在我的工作服务器错误TCPDF错误:[图片]无法获取图像:

cakephp tcpdf图片错误[图片]无法获取图片

< a href =https://stackoverflow.com/questions/7665540/tcpdf-error-image-unable-to-get-image> TCPDF错误:[图片]无法获取图片

推荐答案

这可能是由于 filesize() 无法 stat() 远程图像文件e通过 HTTP包装器(因为包装器不支持它)。

This might be due to filesize() failing to stat() the remote image file via the HTTP wrapper (since the wrapper doesn't support it).

根据 TCPDF图片()方法文档您可以通过在 @ 符号前面添加图像数据来直接传递图像数据。所以你可以得到原始图像数据然后传递给TCPDF,如下所示:

According to the TCPDF image() method documentation you can pass the image data in directly by prepending it with an @ symbol. So you could get the raw image data and then pass it to TCPDF like so:

$img = file_get_contents('http://example.com/wp-content/themes/example/map_image_leasing.php/?city=Calgary&suit_type=&min_area=&max_area=');

$pdf->Image('@' . $img, 55, 19, '', '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);

请注意,我没有对此进行测试(并且TCPDF文档很稀疏),因此您可能需要尝试一下以使其正常工作。

Note that I haven't tested this (and the TCPDF documentation is sparse) so you might need to experiment a little to get it to work correctly.

编辑:

这是一个完全有效的例子(在我的电脑上)。使用此选项可测试您是否可以成功检索图像并将PDF输出到浏览器。当然,您需要为图像设置已知的有效路径!

This is a fully working example (on my PC). Use this to test if you can successfully retrieve the image and output the PDF to your browser. Of course you'll need to set a known valid path for the image!

<?php

require './tcpdf/tcpdf.php';

$pdf = new TCPDF();

$pdf->AddPage();

$img = file_get_contents('http://path/to/your.jpg');
$pdf->Image('@' . $img);

$pdf->Output();

?>

这篇关于TCPDF错误:无法获取图像的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆