Tu masz moją funkcję która to robi:
Opis paramterów:
$img_name = nazwa pliku (np. obraz.jpg)
$photo_dir = katalog z plikiem
$thumb_dir = katalog so którego zostanie zapisany przekonwertowany plik
$max_width = maksymalna szerokosc
$max_height = maksymalna wysokosc
$proportion=false = czy ma zachowac proporcje czy nie - w twoim przypadku
trueW przypadku prawidłowego skonwertowania obrazka zwraca ściezke do niego.
Kod
function ImageConvert($img_name,$photo_dir,$thumb_dir, $max_width,$max_height,$proportion=false){
$img_path = $photo_dir.$img_name;
$thumb_path = $thumb_dir.$img_name;
if(file_exists($img_path)) {
$img_attr = getimagesize($img_path);
if($proportion){
if($img_attr[0]>$img_attr[1])
$scale = $img_attr[0] / $max_width;
else $scale = $img_attr[1] / $max_height;
$w = floor($img_attr[0]/$scale);
$h = floor($img_attr[1]/$scale);
}else{
$w = $max_width;
$h = $max_height;
}
$thumb = imagecreatetruecolor($w,$h);
$result = @imagecopyresampled($thumb, imagecreatefromjpeg($img_path), 0, 0, 0, 0, $w, $h, $img_attr[0], $img_attr[1]);
if($result)
@imagejpeg($thumb,$thumb_path,85);
if($result) return $thumb_path; else return $result;
} else return -1;
}