I really do not know any PHP but I'd love to do one simple thing:
I access a php page from within a <img src="/myhumbleimage.php" />
and I'd like to have an image returned from another URL.
I came up with:
<?php
header('Content-Type: image/png');
readfile('i' . rand(1,3) . '.png');
exit;
And it works:
Avatar selection http://vercas.webuda.com/img.php?.png
(Reload the page a few times!)
Check out readfile().
The basic idea is you send the appropriate MIME type headers (using header()) then deliver the file contents using readfile()
.
For example
<?php
// myhumbleimage.php
// Do whatever myhumbleimage.php does before the image is delivered
header('Content-Type: image/jpeg');
readfile('path/or/url/of/image/file.jpg');
exit;
Why not just reference the image directly then? If you are trying to hide the fact you are pulling an image from an external source, that external source will still be able to tell you are pulling their images.
Otherwise, pass a Content-Type header with the appropriate mime-type and echo the results of file_get_contents($imageUrl)
.
Just generate or read, then output the image using PHP.
...get image data from file or dynamically...
header('Content-type: image/png'); //or whatever MIME type
print $imgdata;
Or check out this: http://php.net/manual/en/function.imagepng.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With