View Single Post
  #2 (permalink)  
Old Jul 15th, 2007, 12:39
balaclave balaclave is offline
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: need help resizing images

Quote:
PHP: Select all

global $HTTP_POST_VARS,$HTTP_GET_VARS,$HTTP_SESSION_VARS,$HTTP_POST_FILES;

global 
$_SESSION;

if (
$HTTP_POST_VARS!="")
    
$_POST=$HTTP_POST_VARS;

if (
$HTTP_GET_VARS!="")
    
$_GET=$HTTP_GET_VARS;

if (
$HTTP_SESSION_VARS!="")
   
$_SESSION=$HTTP_SESSION_VARS;

if (
$HTTP_POST_FILES!="")
   
$_FILES=$HTTP_POST_FILES
What version of PHP are you using?

After PHP 4.1.0, $_SESSION, $_POST, $_FILES, etc, are all superglobals.
I.e. They are predefined variables that are already global. $HTTP_*_VARS is deprecated; just use $_*.
$_SESSION is a superglobal, so you don't need to make it global - it automatically is.

On to the image sizes.
You have this in your code...does it work for you?
PHP: Select all

list($foo$width$bar$height) = explode("\""$size[3]); 

It seems that you are splitting the img tag string to find the width and height.
This would probably be better:
PHP: Select all

$width $size[0];

$height $size[1];

// or

list($width$height) = getimagesize($_FILES['the_file']['tmp_name']); 
Also, in $size[3], height comes before width, but in your list() width comes before height.

On to the resizing:
PHP: Select all

           if($allowed)

            {
            
                
$size getimagesize($_FILES['the_file']['tmp_name']);
                
$width $size[0];
                
// image width
                
$height $size[1];
                
// image height

                
if($width $max_image_size || $height $max_image_size) {
                
// since max_image_width and max_image_height are both 350, might as well just use one variable.

                     
if ($width $height) {
                     
// if the width is more than the height, resize image according to width proportions
                     
$ratio = ($max_image_size $width);
                     
// ratio to resize by == max size of image divided by width
                     

                     else {
                     
// if the height is more than the width, resize image according to height proportions
                     
$ratio = ($max_image_size $height);
                     }
               

                     
$newwidth round($width $ratio);
                     
// new width
                     
$newheight round($height $ratio);
                     
// new height

                     
$newimage imagecreatetruecolor($newwidth$newheight);
                     
// start making new image
                     
$source imagecreatefromjpeg($_FILES['the_file']['tmp_name']);
                     
// original image
 
                     
imagecopyresized($newimage$source0000$newwidth$newheight$width$height);
                     
// resize image

                     
imagejpeg($newimage); // or whatever image type it is
                     // make new image

                
}
             } 

Last edited by balaclave; Jul 15th, 2007 at 12:50.
Reply With Quote