Skip to Content Skip to Menu

Maintain PNG transparency for image upload

  • softforge
  • softforge
  • OFFLINE
  • Posts: 129
  • Thanks: 21
  • Karma: 12
11 years 11 months ago - 11 years 11 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:
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! :)

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

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum