PDA

View Full Version : Image Gallery change original image size


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.

72dpi
01-12-2006, 11:51 PM
Beautiful Heavy.
Thanks for this one!

abcohen
01-13-2006, 04:30 AM
Heavy, you're additions to this board have been GREAT -- keep up the great work!

HeavyEddie
01-13-2006, 11:52 AM
Thanks abcohen... I'm just having fun :)

sc2
04-09-2008, 07:50 AM
Hi, is there any code for this that will work with the latest subdreamer and gd2? I tried searching for the code listed in the first post but it doesn't find any. Much appreciative of anyone who can help! My users often upload huge screenshots, etc, so resizing would e good. I don't want to just use midsized images because I want it larger than my layout can handle.