Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter text overlay on transparent png-24 changes background to black
#1

[eluser]wanderer[/eluser]
I am trying to write some text on a transparent PNG-24 image using the following code:
Code:
$config['source_image'] = '/wamp/www/img/test.png';
$config['new_image'] = '/wamp/www/img/test1.png';
$config['wm_text'] = "TEST TEXT";
$config['wm_type'] = 'text';
$config['wm_font_path'] = './system/fonts/texb.ttf';
$config['wm_font_size'] = '11';
$config['wm_font_color'] = '555555';
$config['wm_vrt_alignment'] = 'top';
$config['wm_hor_alignment'] = 'center';
$config['wm_vrt_offset'] = '77';
$config['wm_hor_offset'] = '3';

$this->image_lib->initialize($config);
$this->image_lib->watermark();

but after writing, the transparent PNG background is being changed into black. Any help would be appreciated.
#2

[eluser]Ckirk[/eluser]
Is it actually picking up the source_image (/wamp/www/img/test.png) because I just read the library code and it should by all accounts retain the transparency of a PNG
#3

[eluser]wanderer[/eluser]
Yes it is picking the right image. BTW, it's retaining transparency on PNG-8 but not PNG-24.
#4

[eluser]Ckirk[/eluser]
Ah hold on.. PNG-24. I should have spotted that.
PNG-24 doesn't support alpha transparency but PNG-32 does. Try changing your original image to PNG-32 then do it again.

Let us know how you get on
#5

[eluser]wanderer[/eluser]
Thank you for your reply. Actually I am saving it in photoshop as 24 bit and I am ticking the "transparency" option so I am sure it's adding a transparent layer and if I check the resulting image details, it shows 32-bit image and it's transparent. But once the image is processed by CI text overlay, it's being converted to a 24-bit image without the alpha channel. Both files attached, I appreciate your time.
#6

[eluser]wanderer[/eluser]
Any luck?
#7

[eluser]wanderer[/eluser]
For anybody who has been searching for this, finally I've paid somebody to resolve the issue for me. In order to solve it, you have to edit:

system\libraries\Image_lib.php

and add the following code:

Code:
if ($this->image_type === 3)
{
imagealphablending($src_img, FALSE);
imagesavealpha($src_img, TRUE);
}

after lines: 1092 and 1098
#8

[eluser]Unknown[/eluser]
FYI, you could also just edit the config file that 'wanderer' posted and ad:

$config['imagealphablending'] = TRUE;
$config['imagesavealpha'] = TRUE;




Theme © iAndrew 2016 - Forum software by © MyBB