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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP/PNG Alpha Blending Problem

  • 20-11-2008 5: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