The important points is that you must send a Content-Type header. Also, you must be careful not include any extra white space (like newlines) in your file before or after the <?php ... ?>
tags.
As suggested in the comments, you can avoid the danger of extra white space at the end of your script by omitting the ?>
tag!
<?php
$img = './test.png';
$fp =fopen($img, 'rb');
//send the right headers
header("Content-Type: image/png");
header("Content-Length: ".filesize($img));
//dump the picture and stop the script
fpassthru($fp);
exit;
?>