I have a script for uploading pictures, and making a thumbular and it works just fine, it uploads a picture, and makes a thumb with tb_ prefix.
Now, the problem is that the script doesent resize the original image, it only makes a thumb of some size i define in the script. I would like this script to make a thumb, as it does already, but i also would like it to resize the original image to some size, for example 800x600, so at the end i get 100x100 tumb and 800x600 pic.
the script :
Code: Select all
// UPLOAD !!!!
// initialization
// Fetch the photo caption array
while( $counter <= count($photos_uploaded) )
{
if($photos_uploaded['size'][$counter] > 0)
{
if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types))
{
$result_final .= "File ".($counter+1)." is not a photo<br />";
}
else
{
mysql_query( "INSERT INTO rabljena_plovila_slike (`photo_filename`,`ID`) VALUES('0','$zadnji_id')" );
$new_id = mysql_insert_id();
$filetype = $photos_uploaded['type'][$counter];
$extention = $known_photo_types[$filetype];
$filename = $new_id.".".$extention;
mysql_query( "UPDATE rabljena_plovila_slike SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );
// Store the orignal file
copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$filename);
// Let's get the Thumbnail size
$size = GetImageSize( $images_dir."/".$filename );
if($size[0] > $size[1])
{
$thumbnail_width = 100;
$thumbnail_height = (int)(100 * $size[1] / $size[0]);
}
else
{
$thumbnail_width = (int)(100 * $size[0] / $size[1]);
$thumbnail_height = 100;
}
// Build Thumbnail with GD 2.x.x, you can use the other described methods too
$function_suffix = $gd_function_suffix[$filetype];
$function_to_read = 'ImageCreateFrom' . $function_suffix;
$function_to_write = 'Image' . $function_suffix;
// Read the source file
$source_handle = $function_to_read($images_dir . '/' . $filename);
if ($source_handle) {
// Let's create a blank image for the thumbnail
$destination_handle =
ImageCreateTrueColor($thumbnail_width, $thumbnail_height);
// Now we resize it
ImageCopyResampled($destination_handle, $source_handle,0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1]);
}
// Let's save the thumbnail
$function_to_write($destination_handle, $images_dir . '/tb_' . $filename);
ImageDestroy($destination_handle );
//
$result_final .= "<img src='".$images_dir. "/tb_".$filename."' /> File ".($counter+1)." Added<br />";
}
}
$counter++;
}
// END UPLOADthx in advanced.
feyd | Please review how to post code using
Code: Select all
andCode: Select all
tags. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]