I am uploading a PNG with transparency to a CB image field and I need to keep the alpha channel. I hacked around and have achieved this with the following change.
In administrator/components/com_comprofiler/imgToolbox.class.php (CB v1.8.1) we have the following on line 431 and 432:
Code:
$background_color = imagecolorallocate( $dst_img, 255, 255, 255 ); // white background for images with transparency
ImageFilledRectangle($dst_img, 0, 0, $destWidth, $destHeight, $background_color);
Simply change these 2 line to the following 7 lines:
Code:
if (function_exists('imagealphablending')) {
imagealphablending($dst_img, false);
imagesavealpha($dst_img, true);
} else {
$background_color = imagecolorallocate( $dst_img, 255, 255, 255 ); // white background for images with transparency
ImageFilledRectangle($dst_img, 0, 0, $destWidth, $destHeight, $background_color);
}
If the server supports it, the alpha channel is maintained when uploading a PNG and if not, the background is made white like the current behaviour.
I hope this change can make it into the next version as I think it is a useful improvement that could benefit many people.
Thanks for considering!