This is some old code I used to generate a thumbnail from an uploaded image, which may help.
For reference, check out the
PHP image function documentation.
Code:
$fullsize = $user_id . "_" . time() . "_" . $_FILES['shot']['name'];
$thumb = "thumb_" . $user_id . "_" . time() . "_" . $_FILES['shot']['name'];
move_uploaded_file( $_FILES['shot']['tmp_name'], $shot_directory . "/" . $fullsize );
list( $width, $height, $type, $attr ) = getimagesize( $shot_directory . "/" . $fullsize );
if ( $type == 1 )
$src = imagecreatefromgif( $shot_directory . "/" . $fullsize );
else if ( $type == 2 )
$src = imagecreatefromjpeg( $shot_directory . "/" . $fullsize );
else
return "ERROR: This gallery only supports JPG and GIF file formats";
// creating a thumbnail ----------------------------------------------------------
$multiplier = 160 / $width;
$new_width = 160;
$new_height = round( $height * $multiplier );
if ( $new_height > 160 ) {
$multiplier = 0;
$new_height = 0;
$new_width = 0;
$multiplier = 160 / $height;
$new_height = 160;
$new_width = round( $width * $multiplier );
}
$dest = imagecreatetruecolor( $new_width, $new_height );
imageCopyResampled( $dest, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
imagejpeg( $dest, $shot_directory . "/" . $thumb );