HeavyEddie
01-12-2006, 10:53 PM
Now that it isn't unusual for an image from a camera to be absolutely huge, you may want to resize an image if they uploaded something larger than you wish.
Find this:
****// read the source file
****$source_handle = $function_to_read ( $imagesdir."/".$filename );
Add this just below:
//Resize the image if needed
********$newimage_max_width = 640;
********$newimage_max_height = 480;
********
********if($size[0] > newimage_max_width || $size[1] > newimage_max_height)
************{
************if($size[0] > $size[1])
************{
******************$newimage_height = (int)($newimage_max_width * $size[1] / $size[0]);
************}else {
******************$newimage_width = (int)($newimage_max_height * $size[0] / $size[1]);
**************}
**************
****************if($gdselected == 2)
****************{
**********************$newimage_destination_handle = ImageCreateTrueColor($newimage_max_width, $newimage_max_height );
**********************ImageCopyResampled($newimage _destination_handle, $source_handle, 0, 0, 0, 0, $newimage_max_width, $newimage_max_height, $size[0], $size[1] );
********************}else if($gdselected == 1)
********************{
**********************$newimage_destination_handle = ImageCreate($thumbnail_width, $thumbnail_height );
**********************ImageCopyResized($newimage_d estination_handle, $source_handle, 0, 0, 0, 0, $newimage_max_width, $newimage_max_height, $size[0], $size[1] );
********************}
********************$function_to_write( $newimage_destination_handle, $imagesdir."/".$filename );
********************ImageDestroy($newimage_destina tion_handle );
************}
// END
Change the newimage_max_width & newimage_max_height variables if you wish something differnt. i.e. 800x600.
I'm not sure if my code for GD1 will actually work since I have no way to test it... but I think I nailed it. Let me know if you have any problems.
Find this:
****// read the source file
****$source_handle = $function_to_read ( $imagesdir."/".$filename );
Add this just below:
//Resize the image if needed
********$newimage_max_width = 640;
********$newimage_max_height = 480;
********
********if($size[0] > newimage_max_width || $size[1] > newimage_max_height)
************{
************if($size[0] > $size[1])
************{
******************$newimage_height = (int)($newimage_max_width * $size[1] / $size[0]);
************}else {
******************$newimage_width = (int)($newimage_max_height * $size[0] / $size[1]);
**************}
**************
****************if($gdselected == 2)
****************{
**********************$newimage_destination_handle = ImageCreateTrueColor($newimage_max_width, $newimage_max_height );
**********************ImageCopyResampled($newimage _destination_handle, $source_handle, 0, 0, 0, 0, $newimage_max_width, $newimage_max_height, $size[0], $size[1] );
********************}else if($gdselected == 1)
********************{
**********************$newimage_destination_handle = ImageCreate($thumbnail_width, $thumbnail_height );
**********************ImageCopyResized($newimage_d estination_handle, $source_handle, 0, 0, 0, 0, $newimage_max_width, $newimage_max_height, $size[0], $size[1] );
********************}
********************$function_to_write( $newimage_destination_handle, $imagesdir."/".$filename );
********************ImageDestroy($newimage_destina tion_handle );
************}
// END
Change the newimage_max_width & newimage_max_height variables if you wish something differnt. i.e. 800x600.
I'm not sure if my code for GD1 will actually work since I have no way to test it... but I think I nailed it. Let me know if you have any problems.