1

I am creating a PDF with fpdf I can insert an image such as

$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

<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?

1
  • you could probably edit the FPDF function to allow it. its an FPDF error, not a php one Commented May 14, 2014 at 2:18

1 Answer 1

3
$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
Sign up to request clarification or add additional context in comments.

1 Comment

Works great! only thing is FPDF requires a extension type - or a explict type - so also needs the extension in the param list

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.