| | |
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.
http://syntax.cwarn23.net/
My favourite PC. - Oopy Doopy Do 2U2!
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - Oopy Doopy Do 2U2!
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
Views: 1064 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary bounce broken cakephp checkbox class cms code computing cron curl database date delete directory display domain download dynamic echo email error file files folder form forms function functions google href htaccess html image include indentedsubcategory insert integration ip java javascript joomla limit link load login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote return script search select server sessions sms soap source space speed sql structure syntax system table tutorial update upload url validation validator variable video web xml youtube






