View Single Post
Old 05-24-2007, 09:25 AM   #4 (permalink)
seretogis
Huggles, sir?
 
seretogis's Avatar
 
Location: Seattle
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 );
__________________
seretogis - sieg heil
perfect little dream the kind that hurts the most, forgot how it feels well almost
no one to blame always the same, open my eyes wake up in flames

Last edited by seretogis; 05-24-2007 at 09:31 AM..
seretogis is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54