update page now

Voting

: eight minus four?
(Example: nine)

The Note You're Voting On

jon at driestone dot com
21 years ago
imagerotate does not preserve the alpha channel, so if you want to rotate a PNG you need to get 
creative. I don't see any command to retrieve the alpha information from an image (as far as 
I could see,) so you'll have to do a bit of manual labor before hand. In my case I created a 
second PNG file with the alpha saved as RGB data and manually "copied" the data from source 
to destination:

<?php
    function alpha_rotate($dst,$src,$rotate,$offsetX,$offsetY){

        $top = imagecreatefrompng("image_processing/shadow.png");
        $top_alpha = imagecreatefrompng("image_processing/shadow_alpha.png");
                
        imagecopyresampled($top,$src,0,0,0,0,100,100,100,100);
                
        $top = imagerotate($top,$rotate,0x000000);
        $top_alpha = imagerotate($top_alpha,$rotate,0x000000);
    
    
        for ($theX=0;$theX<imagesx($top);$theX++){
            for ($theY=0;$theY<imagesy($top);$theY++){
    
                $rgb = imagecolorat($top,$theX,$theY);
                $r = ($rgb >> 16) & 0xFF;
                $g = ($rgb >> 8) & 0xFF;
                $b = $rgb & 0xFF;
                
                $rgb = imagecolorat($top_alpha,$theX,$theY);
                $a = $rgb & 0xFF;
                $a = 127-floor($a/2);

                $myColor = imagecolorallocatealpha($top,$r,$g,$b,$a);
                imagesetpixel($dst,($theX+$offsetX),($theY+$offsetY),$myColor);    
            }
        }
    }
?>

<< Back to user notes page

To Top