function inserisci_p($grande,$piccola){
//quì setto le variabili
$image=$grande;//immagine originale
$newimage = "$piccola";//destinazione e nome dell'immagine ridimensionata
$image_quality = 80;//qualità dell'immagine
$addborder = 1;//imposti a 1 se vuoi aggiungere il bordo
$max_height = 150;//massima altezza dell'immagine
$max_width = 230;//massima larghezza dell'immagine

//codice che mi crea l'immagine
$src_img = ImageCreateFromJpeg($image);
$orig_x = ImageSX($src_img);
$orig_y = ImageSY($src_img);

$new_y = $max_height;
$new_x = $orig_x/($orig_y/$max_height);

if ($new_x > $max_width) {
$new_x = $max_width;
$new_y = $orig_y/($orig_x/$max_width);
}

$dst_img = ImageCreateTrueColor($new_x,$new_y);
ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $new_x, $new_y, $orig_x, $orig_y);

if ($addborder == 1) {
$black = ImageColorAllocate($dst_img, 0, 0, 0);
ImageSetThickness($dst_img, 1);
ImageLine($dst_img, 0, 0, $new_x, 0, $black);
ImageLine($dst_img, 0, 0, 0, $new_y, $black);
ImageLine($dst_img, $new_x-1, 0, $new_x-1, $new_y, $black);
ImageLine($dst_img, 0, $new_y-1, $new_x, $new_y-1, $black);
}
ImageJpeg($dst_img, $newimage, $image_quality);
ImageDestroy($src_img);
ImageDestroy($dst_img);
}

Io uso questa funzione è ottima xkè fa anke dei calcoli per nn sfasare l'immagine ridimensionata.
Ad esempio se l'immagine è rettangolare, l'immagine ridimensionata sarà un rettangolo.