Codice PHP:
$fullsize=imagecreatefromjpeg("images/gallery/$uploadedfile_name");
$fullsize_height=imagesy($fullsize);
$fullsize_width=imagesx($fullsize);

if(
$fullsize_width>$fullsize_height){
$thumb_width=120;
$thumb_height=90;
if(
$fullsize_width>799){
$photo_width=800;
$photo_height=600;
}
if(
$fullsize_width<799){
$photo_width=640;
$photo_height=480;
}
}

else if(
$fullsize_width<$fullsize_height){
$thumb_width=90;
$thumb_height=120;
if(
$fullsize_width>599){
$photo_width=600;
$photo_height=800;
}
if(
$fullsize_width<599){
$photo_width=480;
$photo_height=640;
}
}

$thumb=imagecreatetruecolor($thumb_width,$thumb_height);
$photo=imagecreatetruecolor($photo_width,$photo_height);
imagecopyresampled($thumb,$fullsize,0,0,0,0,$thumb_width,$thumb_height,$fullsize_width,$fullsize_height);
imagecopyresampled($photo,$fullsize,0,0,0,0,$photo_width,$photo_height,$fullsize_width,$fullsize_height);
 
imagejpeg($thumb,"images/gallery/$lastid1.th.jpg");
imagejpeg($photo,"images/gallery/$lastid1.jpg");
imagedestroy($fullsize);
imagedestroy($thumb);
imagedestroy($photo);
imagedestroy($uploadedfile);
imagedestroy($uploadedfile_name);