0

Hi all ,
what i want to do is to resample my large image into smaller resolution image and save it on the server, but the output image is corrupted when i open it in windows image viewer
:(:(
please help me , here is the code .

// The file
$filename = 'd.png';
$percent = 0.5;

// Content type
 

// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = 400;
$new_height = 400;

// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefrompng($filename);
imagealphablending($im_dest, false);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagesavealpha($image_p, true);
// Output
imagepng($image_e,'aa.png',0);

the output image is attached too ,

3
Contributors
3
Replies
5
Views
8 Years
Discussion Span
Last Post by msi_333
0

Found your problem which I had too when I did my first GD script the last line is incorrect as it has an unsigned variable within the function.

imagepng($image_e,'aa.png',0);

So replace the above with below

imagepng($image_p,'aa.png',0);

Notice the letter 'e' in the first box and the letter 'p' in the second box (after the word image). That is your bug. Although your script shows the letter 'e', it needs to be replaced with the letter 'p'. So the overall code will be:

// The file
$filename = 'd.png';
$percent = 0.5;
 
// Content type
 
 
// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = 400;
$new_height = 400;

// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefrompng($filename);
imagealphablending($im_dest, false);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagesavealpha($image_p, true);
// Output
imagepng($image_p,'aa.png',0); //this is the line that has been changed
0

thank you:) , how to make the quality of the output image maximum ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.