If you are calling them with PHP, could you use some sort of trim() function when you call the image?
????
$image = " image.gif"
echo trim($image) // "image.gif"
Then if you are using a bunch of them, you would set an array, but my suggestions on arrays might not be very helpful.