What are potential pitfalls when rotating PNG images in PHP and maintaining transparency?
When rotating PNG images in PHP and maintaining transparency, a potential pitfall is that the transparency may be lost or distorted during the rotation process. To solve this issue, you can use the `imagealphablending()` and `imagesavealpha()` functions in PHP to preserve the transparency of the image while rotating it.
// Load the PNG image
$source = imagecreatefrompng('image.png');
// Enable alpha blending
imagealphablending($source, true);
// Preserve transparency
imagesavealpha($source, true);
// Rotate the image 90 degrees clockwise
$rotated = imagerotate($source, 90, 0);
// Save the rotated image
imagepng($rotated, 'rotated_image.png');
// Free up memory
imagedestroy($source);
imagedestroy($rotated);