简体   繁体   English

如何从存储为变量的php文件中返回二进制图像?

[英]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.

相关问题 如何以二进制安全的方式从多字节 PHP 字符串变量中获取单个字节? - How can I get the single bytes from a multibyte PHP string variable in a binary-safe way? 如何从 PHP 获取 PHP 二进制文件的路径? - How can I get the path of the PHP binary from PHP? 如何使用php文件中的GET获取在.js文件中声明的变量? - How can I use a GET from my php file, to get a variable that I declared in my .js file? 如何从使用 php 存储为 md5 文件的数据库中获取数据 - How can i get the data from database which is stored as md5 file using php 如何从CodeIgniter存储的变量中获取JQuery中的值 - How can I get value in JQuery from variable stored with CodeIgniter 在PHP中,在使用fopen()将文件指针资源分配给变量之后,如何从变量中获取文件名? - In PHP, after assigning a file pointer resource to a variable with fopen(), how can I get the file name from the variable? 我在一个php文件中声明了一个变量并给了一个值,我该如何将该变量与另一个php文件中存储的值一起使用? - I have a variable declared and given a value in one php file, how can I use that variable with the value stored in it in another php file? 如何使用php将图像转换为二进制图像? - how can i convert image to binary image using php? 如何从另一个文件获取变量的值到函数php中? - How can I get the value of a variable from another file into the function php? 如何在PHP中从对象属性中获取值并将路径存储在变量中? - How can I get in PHP the value out of an object attribute with the path stored in a variable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM