Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP/PNG Alpha Blending Problem

  • 20-11-2008 06:58PM
    #1
    Registered Users, Registered Users 2 Posts: 9,228 ✭✭✭


    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, Registered Users 2 Posts: 9,228 ✭✭✭Chardee MacDennis


    no one? :(


  • Registered Users, Registered Users 2 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, Registered Users 2 Posts: 9,228 ✭✭✭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