Skip to content

gd imagettftext characters overlap when text isn't horizontal, when vertical all characters are on top of each other. #15815

@ghpille

Description

@ghpille

Description

The following code:

<?php
   $gdfont = '/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf';
   $image = imageCreate(640,480);
   $colorRed = imageColorAllocate($image, 255,0,0);
   $colorYellow = imageColorAllocate($image, 255,255,0);
   imageFilledRectangle($image, 50, 50, 590, 430, $colorYellow);
   $colorBlack = imagecolorallocate($image, 0, 0, 0);
     
   // add text
     
   $i = 100;
   $c = 0;
   $x2 = 0;
   $y2 = 100;
   for ($a=0; $a<=360; $a+=15) {
     $colorX = imagecolorallocate($image,$c,$c,$c);
     $b = imagettftext($image,12,$a,$i+$x2,$i+$y2,$colorX,$gdfont,
                       "Hello, Worldy! $a/$c");
     imagepolygon($image,$b,$colorX);
     if ($c > 0) {
       if (($a % 90) == 0) {
         switch ($a / 90) {
           case 1:
             $x2 = 250;
             $y2 = 0;
             break;
           case 2:
             $x2 = 0;
             $y2 = 300;
             break;
           case 3:
             $x2 = 250;
             $y2 = 200;
             break;
         }
       }
     }
     $c += 8;
   }

   // Set type of image and send the output
   header("Content-type: image/jpeg");
   imageJpeg($image);
   imageDestroy($image);
?>

Resulted in this output:
gd

But I expected this output instead:
Where even a vertical text is legible.

PHP Version

PHP 8.2.20

Operating System

Devuan Excalibur (≃Debian testing)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions