| | |
GD imagepng function produce corrupted image file
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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 output image is attached too ,
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)
// 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 ,
Last edited by msi_333; Oct 2nd, 2008 at 12:12 am.
Just walk beside me and be my friend
Programming forums,phpbb3 Styles,
Java Forums,Web Development Forums
Programming forums,phpbb3 Styles,
Java Forums,Web Development Forums
maybe you are having the same problem as this guy:
http://us.php.net/manual/en/function.imagepng.php#79150
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.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
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.
So replace the above with below
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)
imagepng($image_e,'aa.png',0);
php Syntax (Toggle Plain Text)
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)
// 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
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
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
thank you
, how to make the quality of the output image maximum ?
, how to make the quality of the output image maximum ? Last edited by msi_333; Oct 2nd, 2008 at 10:59 am.
Just walk beside me and be my friend
Programming forums,phpbb3 Styles,
Java Forums,Web Development Forums
Programming forums,phpbb3 Styles,
Java Forums,Web Development Forums
![]() |
Other Threads in the PHP Forum
- Previous Thread: Barcode integration with PHP
- Next Thread: Problems with my Login
| Thread Tools | Search this Thread |
ajax apache api array beginner beneath binary broadband broken button cakephp checkbox class cms code countingeverycharactersfromastring crack cron curl database date decode display dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link links login mail match md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf php problem protocol query radio random recursion regex remote script search server session sessions sms smtp soap source space sql strip_tags survey syntax system table tutorial undefined update upload url validator variable video virus votedown web window.onbeforeunload=closeme; xml youtube






