Reputation: 5737
I'm developing a web-service in PHP
where I generate a URL for google static maps
For example:
http://maps.googleapis.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=400x400&sensor=false
I need to get that png
image and return it as image:
$fullURL = 'http://maps.googleapis.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=400x400&sensor=false';
$img = file_get_contents($fullURL);
header("Content-Type: image/png");
header("Content-Length: " . filesize($img));
echo $img;
when I run the google url in browser I see the image and get:
but when I run my page with the code above I don't see the image and it's size is different:
How to do that right?
(my service suppose to return the same as google original url, png file).
Upvotes: 0
Views: 875
Reputation: 30051
I think the problem is that you're using filesize()
on the image content. Try using strlen()
or similar:
$fullURL = 'http://maps.googleapis.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=400x400&sensor=false';
$img = file_get_contents($fullURL);
header("Content-Type: image/png");
header("Content-Length: " . strlen($img));
echo $img;
Upvotes: 1