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?