If the image is heading for a browser inside an <img>
tag, then you can get the browser to rescale it by changing the width
attribute.
Otherwise you need to grab the file and rescale it in your PHP code before outputting it.
You can use imagecopyresampled() to do that, calculating the height. Then outputting the result.
Example, following on from obtaining the image in to $file
from the code above.
$img = @imagecreatefromstring($file);
if ($img === false) {
echo $file;
exit;
}
$width = imagesx($img);
$height = imagesy($img);
$newWidth = 300;
$ratio = $newWidth / $width;
$newHeight = $ratio * $height;
$resized = @imagecreatetruecolor($newWidth, $newHeight);
if ($resized === false) {
echo $file;
exit;
}
$quality = 90;
if (@imagecopyresampled($resized, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height)) {
@imagejpeg($resized, NULL, $quality);
} else {
echo $file;
}