How do i get a transparent background after rotaing a png image with php?

前端 未结 7 1261
天命终不由人
天命终不由人 2020-12-19 10:38

So I have png image and I rotate it but i get a black background.. or if i do the color code ofr white i get white.. I tried doing this..

$trans = imagecol         


        
7条回答
  •  庸人自扰
    2020-12-19 10:49

    This is what I am using, this work great for .png files with transparent backgrounds. High fives!

    function rotate($degrees) {
    
        // Switch from default counter-clockwise to clockwise
        $degrees = 360 - $degrees; 
    
        // Get the image 
        $source =  imagecreatefrompng("images/image.png");
    
        // Rotate the image
        $rotated_image = imagerotate($source, $degrees, imageColorAllocateAlpha($source, 0, 0, 0, 127));
    
        // Save the rotated image
        imagepng($rotated_image, 'images/rotated_image.png');
    
    }
    

提交回复
热议问题