Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: GD lib with png

  1. #1
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,547
    Thanks
    57
    Thanked 148 Times in 147 Posts

    GD lib with png

    Hi all. Not much of a GD man but i can understand and change to suit. My problem being this code i've wrote when uploading .png images.

    PHP Code:
    <?php
    if(isset($_FILES) && count($_FILES)!=0)
    {
        if(!empty(
    $_FILES['fileToUpload']['tmp_name']))
        {
            if(
    preg_match("#^image/((?:gif)|(?:jpg)|(?:jpeg)|(?:png))$#is"$_FILES['fileToUpload']['type'], $match))
            {
                
    $extention $match[1];
                if(!empty(
    $_POST['fileToUploadName']))
                {
                    
    $filename $_POST['fileToUploadName'].".".$extention;
                }
                else
                {
                    
    $filename $_FILES['fileToUpload']['name'].".".$extention;
                }
                
                
    $image_location $filename;
                if(!
    file_exists($image_location))
                {    
                    
    $uploadedfile $_FILES['fileToUpload']['tmp_name'];
                    if(
    $extention=="gif")
                    {
                        
    $src imagecreatefromgif($uploadedfile);
                    }
                    elseif(
    $extention=="png")
                    {
                        
    $src imagecreatefrompng($uploadedfile);
                    }
                    else
                    {
                        
    $src imagecreatefromjpeg($uploadedfile);
                    }
                    
                    list(
    $width,$height)=getimagesize($uploadedfile);
                
                    
    $newwidth=200;
                    
    $newheight=134;
                    
    $tmp=imagecreatetruecolor($newwidth,$newheight);
                
                    
    imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
                    
                    if(
    $extention=="gif")
                    {
                        if(
    imagegif($tmp,$filename,100))
                        {
                            
    imagedestroy($src);
                            
    imagedestroy($tmp); 
                            echo 
    "upload complete";
                        }
                        else
                        {
                            echo 
    "upload failed";    
                        }
                    }
                    elseif(
    $extention=="png")
                    {
                        if(
    imagepng($tmp,$filename,100))
                        {
                            
    imagedestroy($src);
                            
    imagedestroy($tmp); 
                            echo 
    "upload complete";
                        }
                        else
                        {
                            echo 
    "upload failed";    
                        }
                    }
                    else
                    {
                        if(
    imagejpeg($tmp,$filename,100))
                        {
                            
    imagedestroy($src);
                            
    imagedestroy($tmp); 
                            echo 
    "upload complete";
                        }
                        else
                        {
                            echo 
    "upload failed";    
                        }
                    }
                }
                else
                {
                    echo 
    "file name already exists";    
                }
            }
            else
            {
                echo 
    "please select a valid image file to upload";    
            }
        }
        else
        {
            echo 
    "Please select a file to upload";    
        }
    }
    ?>
    returns error:

    Code:
    Warning: imagepng() [function.imagepng]: gd-png: fatal libpng error: zlib failed to initialize compressor -- stream error in C:\wamp\www\ACTfileUploader\uploader.php on line 58
    
    Warning: imagepng() [function.imagepng]: gd-png error: setjmp returns error condition in C:\wamp\www\ACTfileUploader\uploader.php on line 58
    upload complete
    Last edited by Phil Jackson; 10-28-2009 at 05:05 PM.
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #2
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    This is the problem:

    Quote Originally Posted by Phil Jackson View Post
    PHP Code:
    imagepng($tmp,$filename,100
    Where you have 100, use an integer from 0 to 9 instead.

    Look at the "quality" argument of imagepng in the PHP manual: http://uk.php.net/manual/en/function.imagepng.php
    Die Welt ist ein Irrenhaus und hier ist die Zentrale!

  • Users who have thanked mlse for this post:

    Phil Jackson (10-28-2009)

  • #3
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,547
    Thanks
    57
    Thanked 148 Times in 147 Posts
    good man
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #4
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks

    Gabriel
    -----------------------
    www.gaboesquivel.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •