Here I put this together for you:
<?php
// set the your image directory(from document root)
$image_dir = "./images/";
// make the image name safe
$image_name = stripslashes( $_GET['img'] );
// get all images in the image dir
$images = scandir( $image_dir );
// chop of "." and ".." from the images array
$images = array_slice( $images, 2 );
// if the file doesn't exist die()
if( array_search( $image_name, $images ) === FALSE ) die("<b>Error: </b> Image Not Found!");
// get the contents of the image
$image_contents = file_get_contents( $image_dir . $image_name );
// site mime content-type to whatever the image type is
header("Content-Type: ". mime_content_type( $image_dir . $image_name ) );
// get the image contents
$image_contents = file_get_contents( $image_dir . $image_name );
// display the image
echo $image_contents;
?>
Just save that code into a file. Call it like images.php or something like that.
Then whenever you want to use an image just put:
<img src="imagesg.php?img=1.jpg">
Remember all of these images MUST be in the image directory you specify.
hope it helps! :p