943,888 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1761
  • PHP RSS
Oct 2nd, 2008
0

GD imagepng function produce corrupted image file

Expand Post »
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 .
php Syntax (Toggle Plain Text)
  1.  
  2. // The file
  3. $filename = 'd.png';
  4. $percent = 0.5;
  5.  
  6. // Content type
  7.  
  8.  
  9. // Get new dimensions
  10. list($width, $height) = getimagesize($filename);
  11. $new_width = 400;
  12. $new_height = 400;
  13.  
  14. // Resample
  15. $image_p = imagecreatetruecolor($new_width, $new_height);
  16. $image = imagecreatefrompng($filename);
  17. imagealphablending($im_dest, false);
  18. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  19. imagesavealpha($image_p, true);
  20. // Output
  21. imagepng($image_e,'aa.png',0);

the output image is attached too ,
Attached Thumbnails
Click image for larger version

Name:	untitled.GIF
Views:	28
Size:	46.4 KB
ID:	7586  
Last edited by msi_333; Oct 2nd, 2008 at 12:12 am.
Reputation Points: 10
Solved Threads: 4
Newbie Poster
msi_333 is offline Offline
22 posts
since Jun 2007
Oct 2nd, 2008
0

Re: GD imagepng function produce corrupted image file

maybe you are having the same problem as this guy:
http://us.php.net/manual/en/function.imagepng.php#79150

Quote ...
So instead of just
imagepng($image); //DIDNT WORK--CORUPT IMAGE

This worked
imagepng($image,NULL,0,NULL);
Last edited by R0bb0b; Oct 2nd, 2008 at 12:49 am.
Reputation Points: 358
Solved Threads: 89
Posting Shark
R0bb0b is offline Offline
986 posts
since Jun 2008
Oct 2nd, 2008
0

Re: GD imagepng function produce corrupted image file

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.
php Syntax (Toggle Plain Text)
  1. imagepng($image_e,'aa.png',0);
So replace the above with below
php Syntax (Toggle Plain Text)
  1. 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:
php Syntax (Toggle Plain Text)
  1.  
  2. // The file
  3. $filename = 'd.png';
  4. $percent = 0.5;
  5.  
  6. // Content type
  7.  
  8.  
  9. // Get new dimensions
  10. list($width, $height) = getimagesize($filename);
  11. $new_width = 400;
  12. $new_height = 400;
  13.  
  14. // Resample
  15. $image_p = imagecreatetruecolor($new_width, $new_height);
  16. $image = imagecreatefrompng($filename);
  17. imagealphablending($im_dest, false);
  18. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  19. imagesavealpha($image_p, true);
  20. // Output
  21. imagepng($image_p,'aa.png',0); //this is the line that has been changed
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Oct 2nd, 2008
0

Re: GD imagepng function produce corrupted image file

thank you , how to make the quality of the output image maximum ?
Last edited by msi_333; Oct 2nd, 2008 at 10:59 am.
Reputation Points: 10
Solved Threads: 4
Newbie Poster
msi_333 is offline Offline
22 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Multiple text box query
Next Thread in PHP Forum Timeline: Problems with my Login





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC