Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP/PNG Alpha Blending Problem

Options
  • 20-11-2008 6:58pm
    #1
    Registered Users Posts: 9,225 ✭✭✭


    Hey having some trouble trying to maintain transparency on a png when i create a thumbnail from it, anyone any experience with this? any help would be great, here's what i am currently doing:
        $fileName= "../js/ajaxupload/tees/".$fileName;
        
        list($width, $height) = getimagesize($fileName);
        
        $newwidth = 257;
        $newheight = 197;
        
        $thumb = imagecreatetruecolor($newwidth, $newheight);
        imagealphablending($thumb, true);
        $source = imagecreatefrompng($fileName);
        imagealphablending($source, true);
        
        imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
        
        imagesavealpha($thumb, true);
        imagepng($thumb,$newFilename);
    
    


Comments

  • Registered Users Posts: 9,225 ✭✭✭Chardee MacDennis


    no one? :(


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    I'm guessing you'll have to place the

    [php] imagesavealpha($thumb, true);[/php]

    Before you do the resizing:
    [php]imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);[/php]

    I'm half asleep now but worth a shot anyways.


  • Registered Users Posts: 9,225 ✭✭✭Chardee MacDennis


    got it with this:
    $thumb = imagecreatetruecolor($newwidth, $newheight);
    	imagealphablending($thumb, false);
    	imagesavealpha($thumb, true);  
    	
    	$source = imagecreatefrompng($fileName);
    	imagealphablending($source, true);
    	
    	imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    	
    	imagepng($thumb,$newFilename);
    

    thanks for the help!


Advertisement