|
вот как это делают:
<?php
if ($img) {
$w = imagesx($img);
$h = imagesy($img);
$scale = min($width/$w, $height/$h);
// в переменные width и height считываются выбранные размеры картинки.
if ($scale < 1) {
$new_width = floor($scale*$w);
$new_height = floor($scale*$h);
$img2 = imagecreatetruecolor($new_width, $new_height);
imagefill($img2, 0, 0, 0xFFFFFF);
imagecopyresampled($img2, $img, 0, 0, 0, 0,
$new_width, $new_height, $w, $h);
imagedestroy($img);
$img = $img2;
}
}
header("Content-type: image/jpeg");
imagejpeg($img);
?>
|