Nie latwiej ten obrazek zeskalowac ?
<?php
$filename = $_REQUEST['image'];
$max_width = $_REQUEST['max_width'];
$max_height = $_REQUEST['max_height'];
if (!$max_width)
$max_width = 150;
if (!$max_height)
$max_height = 150;
$width = $size[0];
$height = $size[1];
header('Content-type: '.$size['mime']);
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if ( ($width <= $max_width) && ($height <= $max_height) ) {
$newwidth = $width;
$newheight = $height;
}
elseif (($x_ratio * $height) < $max_height) {
$newheight = ceil($x_ratio * $height); $newwidth = $max_width;
}
else {
$newwidth = ceil($y_ratio * $width); $newheight = $max_height;
}
$thumb = imagecreatetruecolor($newwidth, $newheight);
switch($size['mime']) {
case "image/gif":
$source = imagecreatefromgif($filename);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagegif($thumb);
break;
case "image/jpg":
case "image/pjpeg":
case "image/jpeg":
$source = imagecreatefromjpeg($filename);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb);
break;
case "image/pjpeg":
$source = imagecreatefromjpeg($filename);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb);
break;
case "image/png":
$source = imagecreatefrompng($filename);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpng($thumb);
break;
}
?>
Wywolanie
<img src="image.php?image=urlencode(sciezka do obrazka)&max_height=ilechcesz&max_width=ilechcesz">
Gdzie image.php to ten plik powyzej.