FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Why this PNG code don;t work ?





Philip
Code:

         list($width_orig, $height_orig) = getimagesize($filename);
         $width = 80;
         $height = 80;

            if(substr(strtolower($filename),-3)=="png"){
               header('Content-type: image/png');
               if ($height_orig>=$width_orig){
                  $width = $width_orig*($height/$height_orig);
                  $height = $height_orig*($height/$height_orig);
               }else
               {
                  $width = $width_orig*($width/$width_orig);
                  $height = $height_orig*($width/$width_orig);
               }
               if ($width && ($width_orig < $height_orig)) {
                  $width = ($height / $height_orig) * $width_orig;
               } else {
                  $height = ($width / $width_orig) * $height_orig;
               }
               $image_p = imagecreatetruecolor($width, $height);
               $image = imagecreatefrompng($filename);
               imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
               imagepng($image_p, null, 100);            
            }


what's wrong with my code ? it work when i change all png to jpg and gif, but when using png it seem the image size being zero..

thanks,
a_dubDesign
the first thing I would check is the png format of the png your passing in. After all sorts of drama I had, I learned that GD doesn't have PNG 24 support.
Philip
you mean my code already right, just my server doesn;'t support GD PNG ??
a_dubDesign
Philip wrote:
you mean my code already right, just my server doesn;'t support GD PNG ??

its not the server or your code(from what I can tell it looks right), the issue is with GD(the php library which does all the image functions).

There are two types of PNGs, PNG-8 and PNG-24. The current version of GD only supports PNG-8, not PNG-24. I'm guessing that the image you have is PNG-24, because it is very similar to the issue I had when I was using PNG-24 instead of PNG-8. To fix the problem, change the encoding of the picture when you save it. PNG-8 should be an option in the same drop-box as PNG-24 (like the preset drop-box in photoshop's "save for web" dialog box).

Hope that helps clear things up a bit
Philip
wups,, is there a way to change the GD library ? or checking image what is the PNG format ?
Traveller
Also, don't forget to test your code with Firefox or Opera, since IE is notoriously bad at handling PNG, especially if it contains any transparency.
a_dubDesign
Philip wrote:
wups,, is there a way to change the GD library ?

not unless you're a programming genius

Philip wrote:
or checking image what is the PNG format ?

not that I know of or have seen floating around.
Related topics
Politicaly incorrect blonde jokes
What do you use to make your page layout?
users online, using php and text file
The Next Step?
Can l get a css document to
This C code is little unclear to me.
Why this code should be needed?
Why this code dont work ?
php dynamic graph code not working
mail()
A lot of Bugs in IE6
removing DirectAdmin part of URL makes php code work
server 4 not working code
Problem with code that handles arrays and database updates
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.