Maintain PNG transparency for image upload

11 years 6 months ago - 11 years 6 months ago #210723 by softforge
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:
$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:
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! :)

If you like our plugins, please consider writing a review on the Joomla Extension Directory or the Community Builder Directory ...
The following user(s) said Thank You: newlog, Zorg33

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.158 seconds

Facebook Twitter LinkedIn