Good afternoon from Palo Alto. I'm stuck on a small image processing problem:

I have some PHP code that should take an uploaded JPEG called " imagea " and do four things to it, in this order:
1. Crop EITHER the width OR the height such that the aspect ratio is 4:3 ;
2. Resize the image to 210 pixels : 157 pixels ;
3. Reduce the memory size of the entire image to 50kb or less; and
4. Save the processed image in a folder called "images" as " a$id.jpg ", with $id provided from a prior screen.

1 and 4 are getting done just fine. The problem is that sometimes in the cropping step -- step 2 -- I wind up with a fat black bar along the bottom edge of the image. In addition, I think I neglected to put in code to accomplish step 3, that is, to reduce the memory of the whole file to 50kb or less. Here's the code I have so far:

<?
if (is_uploaded_file($_FILES['imagea']['tmp_name'])) {
$imageSize = getimagesize($_FILES['imagea']['tmp_name']);
$width = $imageSize[0];
$height = $imageSize[1];
$type = $imageSize['mime'];
$size = $_FILES['imagea']['size'];
$newImage = imagecreatetruecolor(210, 157);
$oldImage = imagecreatefromjpeg($_FILES['imagea']['tmp_name']);
$heightFromOld = ($width/1.34);
imagecopyresampled($newImage, $oldImage, 0, 0, 0, 0, 210, 157, $width, $heightFromOld);
imagejpeg($newImage, "images/a$id.jpg");
?>

Please, any suggestions? Thank you.