Reputation: 167
I want to print an image url, but it gives me special characters. I tried every solution in file_get_contents - Special characters in URL - Special case but it didnt solve it.
my code:
$urlgeo = "http://geodata.nationaalgeoregister.nl/top25raster/wms?request=GetMap&service=WMS&version=1.3.0&request=GetMap&layers=top25raster&styles=&bbox=146000,451000,149000,454000&width=600&height=600&srs=EPSG:28992&format=image/png";
print file_get_contents($urlgeo);
Upvotes: 3
Views: 608
Reputation: 3236
If you want to show the image try this:
<?php
$urlgeo = "http://geodata.nationaalgeoregister.nl/top25raster/wms?request=GetMap&service=WMS&version=1.3.0&request=GetMap&layers=top25raster&styles=&bbox=146000,451000,149000,454000&width=600&height=600&srs=EPSG:28992&format=image/png";
echo "<img src='data:image/png;base64," . base64_encode(file_get_contents($urlgeo)) . "'>";
?>
It gets the image and encodes in base64.
And later if you need the raw image data, just base64_decode
it like:
$raw_image = base64_decode($encodedImg):
Where $encodedImg
is the base64 encoded string. The $raw_imag
would contain the raw image data!
Upvotes: 0
Reputation: 2433
You are requesting an PNG Image from the API service, you should use the appropriate headers to display the image,
header('Content-Type: image/png');
$urlgeo = "http://geodata.nationaalgeoregister.nl/top25raster/wms?request=GetMap&service=WMS&version=1.3.0&request=GetMap&layers=top25raster&styles=&bbox=146000,451000,149000,454000&width=600&height=600&srs=EPSG:28992&format=image/png";
print file_get_contents($urlgeo);
Upvotes: 2