[PHP] image resize problem

Glaanieboy

OSNN Veteran Addict
Joined
6 Mar 2002
Messages
2,628
Code:
<?php
$file = $_GET['file'];
list($height,$width,$type,$attr) = getimagesize($file);
$file_info = getimagesize($file);

$new_height = $_GET['max_height'];
$new_width = $_GET['max_width'];

//print $type;
$mime = $file_info['mime'];
//print $mime;
if ($height > $width){
  header("Content-type: $mime");
  $height_calc = $height - $new_height;
  $width_calc = $width - $new_width;
  
  if ($height_calc > $width_calc){
    $calc = $new_height / $height;
    $new_width = $width * $calc;
  }else{
    $calc = $new_width / $width;
    $new_height = $height * $calc;
  }
  if ($type == 3){
    //here is the problem
    $old_img = imagecreatefrompng($file);
    $new_img = imagecreatetruecolor($new_height,$new_width);
 imagecopyresampled($new_img,$old_img,0,0,0,0,$new_width,$new_height,$width,$height);
    imagepng($new_img);
    imagedestroy($new_img);
    imagedestroy($old_img);
  }


}elseif($height < $width){

}else{
}

?>

Don't mind the messyness of the code, it's still a work in progress. Basically the problem resides in the "//Here is the problem" part. I have an image, that must be resized to a calculated new size. It does calculate the sizes correctly, but then I miss about 20% of the image, the right 20% part to be precise. Click here for an example (Click here for the original file).

Can someone look at the code and tell me what's wrong?
 

Geffy

OSNN Veteran Addict
Joined
18 Mar 2002
Messages
7,805
array getimagesize ( string filename [, array imageinfo])

The getimagesize() function will determine the size of any GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP, IFF, JP2, JPX, JB2, JPC, XBM, or WBMP image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag.

Note: Support for JPC, JP2, JPX, JB2, XBM, and WBMP became available in PHP 4.3.2. Support for SWC as of PHP 4.3.0.

Returns an array with 4 elements. Index 0 contains the width of the image in pixels. Index 1 contains the height. Index 2 is a flag indicating the type of the image: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM. These values correspond to the IMAGETYPE constants that were added in PHP 4.3. Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.

an Example from php.net is
Code:
<?php
list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
echo "<img src=\"img/flag.jpg\" $attr alt=\"getimagesize() example\" />";
?>

so it looks like on your list() call you have the $height and the $width getting the wrong values
 

j79zlr

Glaanies script monkey
Political Access
Joined
16 Feb 2003
Messages
2,725
oops, geffy posted that already, ignore/
 

Members online

No members online now.

Latest profile posts

Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.
Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk wrote on Sazar's profile.
Where are you buddy?

Forum statistics

Threads
62,005
Messages
673,461
Members
5,599
Latest member
Larry Chris