php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41666 imageTTFtext without Alpha
Submitted: 2007-06-12 09:43 UTC Modified: 2007-06-12 14:04 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: cyberline at techno4ever dot net Assigned: pajoye (profile)
Status: Not a bug Package: GD related
PHP Version: 5.2.3 OS: Debian 3.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cyberline at techno4ever dot net
New email:
PHP Version: OS:

 

 [2007-06-12 09:43 UTC] cyberline at techno4ever dot net
Description:
------------
imageTTFtext has no alpha in case of using imageCreateFromPNG.
This was OK in PHP 5.2.1

Reproduce code:
---------------
http://web1.server02.quadrat4.de/phpbug/

Expected result:
----------------
Alphablending of the text

Actual result:
--------------
Rough Edges. Look at example.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-12 10:59 UTC] pajoye@php.net
Please provide a link to the original "logo.png" image and to the TTF file.
 [2007-06-12 11:11 UTC] cyberline at techno4ever dot net
The fontfile:

http://web1.server02.quadrat4.de/federation.ttf

The logo:

http://web1.server02.quadrat4.de/logo.png
(I've tested other transparent PNG's with similar results)

Further i've added a sample text with ./arial.ttf
 [2007-06-12 11:45 UTC] pajoye@php.net
Ok, I understand what you mean now.

There is two things. Per default gd does not save the alpha information, you have to enable this mode using:

imagesavealpha($image, true);

The second problem is the blending mode while copying/resizing the embed image. You have to disable the blending operation. Try:

<?php
$image    = imagecreatetruecolor(222, 189);
$embed    = imagecreatefrompng($logofile);
$white    = imagecolorallocate($image, 255, 255, 255);
imagealphablending($image, 0);
imagecopyresized($image, $embed, 0, 0, 0, 0, 222, 189, imagesx($embed), imagesy($embed));
imagettftext($image, 12, 0, 5, 15, $white, $font, $text);
imagesavealpha($image, true);
imagepng($image, $destfile);
imagedestroy($image);

 [2007-06-12 11:54 UTC] cyberline at techno4ever dot net
Now the 5.2.1 working Sample (nok.php) looks fine with imagesavealpha, but take a look at the ok.php with

imagealphablending($image, 0);

So it is not a bug that in 5.2.1 the alpha was enabled by default ?
 [2007-06-12 12:05 UTC] pajoye@php.net
"So it is not a bug that in 5.2.1 the alpha was enabled by default "

I don't have a 5.2.1 to test. The alpha channel is now preserved (the background, the white area around the logo). nok.php is black because you don't save the alpha channel.

I think this bug is not a bug. I close (not a bug > bogus) it now. Please reopen it if you consider that it is not working correctly in 5.2.3 or using snapshot.
 [2007-06-12 12:54 UTC] cyberline at techno4ever dot net
I don't mean the transparent background!

My problem is the text.

Compare:

http://cyberline.ath.cx/phpbug/nok.php (PHP 5.2.1)
with
http://web1.server02.quadrat4.de/phpbug/nok.php (PHP 5.2.3)

Both same Configure.
 [2007-06-12 13:05 UTC] pajoye@php.net
"I don't mean the transparent background!
My problem is the text."

As long as you have no alpha channel, there is no alpha either involved in the text.

The text itself works pretty well here. Your problem looks more like a hinting problem which depends on the freetype version, settings or options. Can you show me a phpinfo and tell me which freetype version you use and on which system.


 [2007-06-12 13:15 UTC] cyberline at techno4ever dot net
http://www.host4ever.de/info.php

Freetype 2.1.7 on Debian 3.1

When it's a Freetype problem, i don't understand why the text looks so since updating PHP to 5.2.3.

The working example at cyberline.ath.cx is Freetype 2.1.7 on Debian 4 with PHP 5.2.1
 [2007-06-12 14:04 UTC] pajoye@php.net
"When it's a Freetype problem, i don't understand why the text looks so since updating PHP to 5.2.3."

As I said, the text problem itself is due to the blending mode and whether or not your save the alpha channel.

If the text is drawn on a fully (or partially) transparent area, the antiliasing will be done using the alpha channel and not using blending. If later on you save the image without alpha, the result is likely to be ugly and the antialiasing effect will look wrong.

But if you disable the alphablending before the copy of the resized logo, it will work well (using 5.2.3):

http://pierre.libgd.org/bugs/bug41666_523_out.png

It may also come from the hinting mode used in freetype, or its options/settings. They have been changed between sarge and etch as far as I remember. But that's not something I can see from phpinfo(). And it is not something I can fix in GD.

"The working example at cyberline.ath.cx is Freetype 2.1.7 on Debian 4
with PHP 5.2.1"

Using debian packages for php, php-gd and freetype?

If yes, I _strongly_ suggest to stop using them for php and php-gd. They use the extern GD library and an outdated version, no update has been done since years and almost all security issues fixed in gd-2.0.34 or php's gd are still present.

Until I figured out a way to get it fixed (I'm working with one of the php debian maintainers and the security team), I can' t support it or even help someone using it.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 13 22:01:31 2024 UTC