Jump to content

[SOLVED] Image Resizing??


lordphate

Recommended Posts

Hi everyone, Okay i have a image resizing script that works well when you're uploading certain photos. BUT I'm wanting to make a Maximum and Minimum requirement...

 

Meaning...

If someone uploads a big photo , i want it to resize to a medium, size(maximum of 250(width) x 250 (height) sounds simple enough right...well i also want to make it where if someone uploads a photo SMALLER than 250 x 250, it doesn't reduce it at all... AND i want to make it where it will keep the same ratio..

 

heres what i have now

 

$size = GetImageSize($photos_uploaded['tmp_name'][$counter]);
            

		    $photo_width = ($size[0] * .50);
                $photo_height = ($size[1] * .50);
            
            $function_suffix = $gd_function_suffix[$filetype];
            $function_to_read = 'ImageCreateFrom' . $function_suffix;
            $function_to_write = 'Image' . $function_suffix;

            $source_handle = $function_to_read($photos_uploaded['tmp_name'][$counter]);

            if ($source_handle)
            {
                
                $destination_handle = ImageCreateTrueColor($photo_width, $photo_height);

                ImageCopyResampled($destination_handle, $source_handle, 0, 0, 0, 0, $photo_width,
                    $photo_height, $size[0], $size[1]);
            }


            $function_to_write($destination_handle, $images_dir . '/' . $filename);

Link to comment
https://forums.phpfreaks.com/topic/38550-solved-image-resizing/
Share on other sites

I would do like this:

 

<?
$max_width = 300; //Set whatever you want
$max_height = 300; //Whatever you want

list($width, $height) = getimagesize('path/to/yourfile.jpg');

if($width <= $max_width && $height <= $max_height)
{
     print "Picture is smaller than 300*300 pixels."; //Or put your code here
}

else //in case image is bigger
{
    PUT YOUR CODE HERE
}
?>

 

Hope this is it

Link to comment
https://forums.phpfreaks.com/topic/38550-solved-image-resizing/#findComment-185470
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.