GD imagepng function produce corrupted image file

Reply

Join Date: Jun 2007
Posts: 13
Reputation: msi_333 is an unknown quantity at this point 
Solved Threads: 1
msi_333's Avatar
msi_333 msi_333 is offline Offline
Newbie Poster

GD imagepng function produce corrupted image file

 
0
  #1
Oct 2nd, 2008
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 .
  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 ,
Last edited by msi_333; Oct 2nd, 2008 at 12:12 am.
Attached Thumbnails
untitled.GIF  
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: GD imagepng function produce corrupted image file

 
0
  #2
Oct 2nd, 2008
maybe you are having the same problem as this guy:
http://us.php.net/manual/en/function.imagepng.php#79150

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.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,476
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 136
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: GD imagepng function produce corrupted image file

 
0
  #3
Oct 2nd, 2008
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.
  1. imagepng($image_e,'aa.png',0);
So replace the above with below
  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:
  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
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 13
Reputation: msi_333 is an unknown quantity at this point 
Solved Threads: 1
msi_333's Avatar
msi_333 msi_333 is offline Offline
Newbie Poster

Re: GD imagepng function produce corrupted image file

 
0
  #4
Oct 2nd, 2008
thank you , how to make the quality of the output image maximum ?
Last edited by msi_333; Oct 2nd, 2008 at 10:59 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC