Prevent getimagesize error

Prevent getimagesize error by first checking whether the file exists.