Added extension detection.

With that little fix, the script will work even with png files.