Hi,
This is code for maintaining aspect ratio of image .
// $source is from where u want to save image.
// $path is from where u pick the image.
list($width, $height) = getimagesize($path) ;
            if( $height > $width)
            {
               $modheight = 50;
               $diff = $height / $modheight;
               $modwidth = $width / $diff;
               $tn = imagecreatetruecolor($modwidth, $modheight) ;
               $image = imagecreatefromjpeg($path) ;
               imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
               imagejpeg($tn, $source, 100) ;
            }
            else
            {
               $modwidth = 50;
               $diff = $width / $modwidth;
               $modheight = $height / $diff;
               $tn = imagecreatetruecolor($modwidth, $modheight) ;
               $image = imagecreatefromjpeg($path) ;
               imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
               imagejpeg($tn, $source, 100) ;
            }
|
My Blog Title
|