I tried literally all day yesterday trying to figure this out. I rotate an image via imagerotate(). I get a black background where the image isn't covering anymore. I have tried everything i cant think of to make that background transparent..
here is my current code..
function rotate($degrees) {
$image = $this->image;
imagealphablending($image, false);
$color = imagecolorallocatealpha($image, 0, 0, 0, 127);
$rotate = imagerotate($image, $degrees, $color);
imagecolortransparent($rotate, $color);
imagesavealpha($image, true);
$this->image = $rotate;
}
I am really starting to get ticked off. Can someone show me some working code? please?
Could it be something wrong with my WAMP server and dreamweaver? because i even tried this.. http://www.exorithm.com/algorithm/view/rotate_image_alpha and it still puts out either a black or white background..
Try setting imagesavealpha() on your rotated image.
Currently you are running imagesavealpha() on your original image. [ eg. imagesavealpha($image, true); ]
Instead you want to run imagesavealpha() on the rotated image and then set $this->image... try:
...
$rotate = imagerotate($image, $degrees, $color);
imagecolortransparent($rotate, $color);
imagesavealpha($rotate, true); // <- using $rotate instead of $image
$this->image = $rotate;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With