You can use getimagesize function just to get the dimensions of an image file. But it should be a file, you have to use this function before you write the contents of the file to the database.
I think you can cope with this problem by using this function.
Good luck