Are you wanting to do this with two files then, or just one?
If you want to keep within the same file, you can do something like this:
<?php
$file = 'image.jpg';
$types = array('jpg', 'jpeg', 'gif', 'png', 'bmp');
$image = $_GET['img'];
$type = strtolower(substr(strrchr($image, "."), 1));
if (isset($image) && file_exists($image) && in_array($type, $types))
{
$image = file_get_contents($image);
header("Content-Type: $type");
echo $image;
}
else
{
echo '<img src="test.php?img=' . $file . '">';
}
?>
Otherwise, with two files, it would probably be easier just to query in the image file itself according to whatever parameters you put for GET. When you put an image tag, it's already been processed independent of your script save for whatever you send through GET or whatever you have saved somewhere (file, database, session, cookie).