Well, you could create an array with the allowed colors and make a little check if the color from the file is correct.
<?php
// read in the string
$string = file_get_contents('file.txt');
// change to lowercase
$color = strToLower($string);
// the allowed colors
$colors = array('green', 'red', 'blue');
// is the color correct?
$color = in_array($color, $colors) ? $color : 'red';
// print the image
echo "<img src=\"$color.gif\" border=\"0\" />";
?>
If the color is invalid, the red one will be shown.