我如何获得二进制图像从存储为变量的php文件返回


How can I get the binary image returned from a php file stored as a variable?

我正在用fpdf创建一个PDF我可以插入像

这样的图像
$pdf->Image('images/image.jpg',0,20,210,80);

我可以插入像

这样的图像
$pdf->Image('http://www.thesearchagents.com/wp-content/uploads/2013/11/Google-Search.jpg',0,20,210,80);
我可以使用 为我的页面提供图像
<img src="http://maps.googleapis.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=400x400&sensor=false" alt="image" height="200" width="300" />

但是如果我尝试

$pdf->Image('http://maps.googleapis.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=400x400&sensor=false',0,20,210,80);

我得到一个错误

"FPDF error: Unsupported image type: php"

因为它不是实际的图像文件,只服务于图像,我猜它不工作设置头

header('Content-Type: image/png');

我能做什么?

我可以捕获图像二进制并将其存储在变量中吗?然后被传递下去?

如果是,那么我的问题是:如何从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