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 ,

Recommended Answers

All 3 Replies

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.