fixed memory leak

I changed the way it loads images so that the garbage collector works.
fixed crashing on non-image file

It checks the last four characters of the filename and compares it to a
list of known image file-extensions.