Or, instead of:
if($width > 2896) return false;
if($height > 2896) return false;
You could use:
if($width * $height > 8388608) return false;
Where 8388608
is 32*1024*1024/4
and allows much more flexibility, because we are going to check the total number of pixels instead of the single sizes, and so a user can upload an image of 3000x1000...