typo3 alpha transparency issue with png_truecolor=1 and libpng2=1

Yesterday night we had the following issue with a typo3 GIFBUILDER object:

While trying to overlay 2 images we lost the alpha-transparency. This happened ONLY if we used [GFX][png_truecolor] = 1.

After hours of “investigations” we managed to create a patch for the file t3lib/class.t3lib_stdgraphic.php that solved our problem. The patch can be found here: http://blog.brasov.cubus.ro/user_uploads/patch_truecolor_png_alpha_transparency.diff

First of all, the relevant configurations:

  • php 5.3.2
  • gdlib 2.0
  • Imagemagick 6.5.7

typo3 configs

  • [GFX][gdlib_png] = 1
  • [GFX][png_truecolor] = 1
  • [GFX][gdlib-2] = 1

excerpt from our typoscript

temp.our_image = IMAGE
temp.our_image.file = GIFBUILDER
temp.our_image.file{
XY = 243,171
transparentBackground = 1

10 = IMAGE
10.file = fileadmin/template/main/pics/img_border.png
10.file.width = 243
10.file.height = 171

20 = IMAGE
20.file.import.field = image
20.file.import = uploads/pics/
20.file.import.listNum = 0
20.file.width = 217c
20.file.height = 150
20.offset = 10,7

The image fileadmin/template/main/pics/img_border.png is has alpha-transparency. The resulting image lost the alpha-transparency when setting [GFX][png_truecolor] = 1 from the install tool.

Our solution was to replace line 3022 in the file t3lib/class.t3lib_stdgraphic.php as follows:

original:
return imagecreatetruecolor($w, $h);

new:
$tmpImg = imagecreatetruecolor($w, $h);
imagealphablending( $tmpImg, false );
imagesavealpha( $tmpImg, true );
return $tmpImg;

And now it works fine.

The patch can be found here: http://blog.brasov.cubus.ro/user_uploads/patch_truecolor_png_alpha_transparency.diff

We filed a bug-report at bugs.typo3.org http://bugs.typo3.org/view.php?id=14602

Leave a Reply

Your email address will not be published. Required fields are marked *