[英]How can I get the binary image returned from a php file stored as a variable?
I am creating a PDF with fpdf I can insert an image such as 我用fpdf创建一个PDF我可以插入一个像这样的图像
$pdf->Image('images/image.jpg',0,20,210,80);
I can insert an image such as 我可以插入一个像这样的图像
$pdf->Image('http://www.thesearchagents.com/wp-content/uploads/2013/11/Google-Search.jpg',0,20,210,80);
in HTML I can serve an image to my page with 在HTML中,我可以将图像提供给我的页面
<img src="http://maps.googleapis.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=400x400&sensor=false" alt="image" height="200" width="300" />
but if I try 但如果我试试
$pdf->Image('http://maps.googleapis.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=400x400&sensor=false',0,20,210,80);
I get an error 我收到一个错误
"FPDF error: Unsupported image type: php"
since it is not the actual image file and is only serving the image I am guessing it does not work with setting the header 因为它不是实际的图像文件,只是服务于图像我猜它不能设置标题
header('Content-Type: image/png');
what can I do? 我能做什么?
Can I capture the image binary and store it in a variable? 我可以捕获图像二进制文件并将其存储在变量中吗? to then be passed along? 然后传递?
If so, then my question is: How do capture the image source from a return of a php file and store it in a variable in php? 如果是这样,那么我的问题是:如何从php文件的返回中捕获图像源并将其存储在php中的变量中?
$bin = file_get_contents('http://your_image_binary_source_url_here'); //fetch binary source
$local_name = "/tmp/".time().'.png';
file_put_contents($local_name, $bin); //create image locally
$pdf->Image($local_name,0,20,210,80); //add image to pdf
unlink($local_name); //delete local image
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.