php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81617 text with 90 degree angle not rendered correctly
Submitted: 2021-11-12 11:52 UTC Modified: 2021-11-19 11:56 UTC
From: dwhile at while dot org dot uk Assigned: cmb (profile)
Status: Not a bug Package: GD related
PHP Version: 8.0.12 OS: Linux
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: dwhile at while dot org dot uk
New email:
PHP Version: OS:

 

 [2021-11-12 11:52 UTC] dwhile at while dot org dot uk
Description:
------------
Using the imagettftext function call with an angle of 90 degrees causes the output to be rendered with each letter of the text on top of one another.

Using the example from the documentation page and changing the angle to 90 causes the problem indeed anything above around 45 degrees shows the same problem.

Test script:
---------------
<?php
header('Content-Type: image/png');
$im = imagecreatetruecolor(400, 30);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
$text = 'Testing...';
$font = '/usr/share/fonts/msttcorefonts/arial.ttf';
imagettftext($im, 20, 90, 11, 21, $grey, $font, $text);
imagettftext($im, 20, 90, 10, 20, $black, $font, $text);
imagepng($im);
imagedestroy($im);
?>

Expected result:
----------------
The text should be rendered vertically reading from bottom to top.

Actual result:
--------------
The rendered text has each character rendered on top of each other.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-12 12:37 UTC] cmb@php.net
-Status: Open +Status: Feedback -Package: *Graphics related +Package: GD related -Assigned To: +Assigned To: cmb
 [2021-11-12 12:37 UTC] cmb@php.net
To clarify, the following slightly modified example

<?php
$im = imagecreatetruecolor(30, 300);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 29, 299, $white);
$text = 'Testing...';
$font = 'C:/Windows/Fonts/Arial.ttf';
imagettftext($im, 20, 90, 26, 221, $grey, $font, $text);
imagettftext($im, 20, 90, 25, 220, $black, $font, $text);
imagepng($im, __DIR__ . "/81617.png");
?>

should give something like <https://imgur.com/a/kH8JmNG>.

It is expected that the text is rendered from bottom to top; if
you want it the other way, use an angle of 270°.

However, if I understand you correctly, in your case the
letters are overlayed.  Which GD version do you use?
 [2021-11-12 12:42 UTC] dwhile at while dot org dot uk
-Status: Feedback +Status: Assigned
 [2021-11-12 12:42 UTC] dwhile at while dot org dot uk
Yes the text characters are overlayed on top of each other.
GD version is 2.3.2
 [2021-11-12 12:50 UTC] dwhile at while dot org dot uk
I have copied your code (and changed the font path to the relevant Linux format.

Output can be seen at <https://www.while.org.uk/try.png>
 [2021-11-12 13:49 UTC] cmb@php.net
> Output can be seen at <https://www.while.org.uk/try.png>

That is indeed broken.  Anyhow, this looks very much like an
upstream issue, so please report there[1].  But before, also check
whether that happens with other fonts as well, and if possible,
try with GD 2.3.3 or even their master HEAD.  Also mention the
freetype version you are using.

[1] <https://github.com/libgd/libgd/issues>
 [2021-11-12 17:16 UTC] cmb@php.net
-Status: Assigned +Status: Suspended
 [2021-11-12 17:16 UTC] cmb@php.net
I'm suspending this ticket until the upstream issue[1] is closed.

[1] <https://github.com/libgd/libgd/issues/790>
 [2021-11-19 11:56 UTC] cmb@php.net
-Status: Suspended +Status: Not a bug
 [2021-11-19 11:56 UTC] cmb@php.net
Since this is apparently an issue in libraqm[1], I'm closing this
as not a bug in GD.

[1] <https://github.com/libgd/libgd/issues/790#issuecomment-974005301>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 03:01:29 2024 UTC