I don't think there's a way to check the size of an image as it's coming in, but you can do some things to it after it's received...
This is a cut-back version of a function I wrote a long time ago to do pretty much what you're talking about. It expects three arguments, an image resource (what was uploaded), and your maximum width and height (in this case 250 and 150 respectively).
It returns a new image resource containing the resized image. Hope this helps... 🙂
function image_resize($im, $maxWidth, $maxHeight) {
$maxAspect = $maxWidth / $maxHeight; //Figure out the aspect ratio of the desired limits
$origWidth = imagesx($im); //Get the width of the uploaded image
$origHeight = imagesy($im); //Get the height of the uploaded image
$origAspect = $origWidth / $origHeight; //Get the aspect ratio of the uploaded image
if (($origWidth > $maxWidth) || ($origHeight > $maxHeight)) { //See if we actually need to do anything
if ($origAspect <= $maxAspect) { //If the aspect ratio of the uploaded image is less than or equal to the target size...
$newWidth = $maxHeight * $origAspect; //Resize the image based on the height
$newHeight = $maxHeight;
} else { //If the ratio is greater...
$newWidth = $maxWidth; //Resize based on width
$newHeight = $maxWidth / $origAspect;
}
$om = imagecreatetruecolor($newWidth, $newHeight); //Create the target image
imagecopyresampled($om, $im, 0, 0, 0, 0, $newWidth, $newHeight, $origWidth, $origHeight); //actually do the resizing
return($om); //Return the result
} else {
return($im); //Or don't do anything and just return the input.
}
}