claviska / SimpleImage

A PHP class that makes working with images and GD as simple as possible.
MIT License
1.38k stars 382 forks source link

#303: Update data type from int to float. #321

Closed edutrul closed 1 year ago

edutrul commented 1 year ago

Related ticket: #303

The text is being cropped every time whenever I use the function textBox

Steps to reproduce:

Use the method textBox

      $phrase = '“Mi mejor amigo, siempre me espera en la puerta. Quiero que siempre esté conmigo. Mi mejor amigo, siempre me espera en la puerta. Quiero que siempre esté conmigo“';
      $image->textBox($phrase, [
              'fontFile' => 'Roboto-Regular.ttf',
              'size' => 18
              'anchor' => 'top left',
              'xOffset' => 0,
              'yOffset' => 0,
              'color' => '#ff9900',
              'width' => 414,
              'align' => left,
          ]
      );

(of course the values do not match exactly the screenshot but can give you an idea).

And you can notice that words "dueño qu" "qu" is missing the "e" which should be "dueño" and the word "que" should be in the next line since there is not enough space.

image

Proposal solution

Change the data type from int to float since there's a previous division for the maxWidth to convert px to pt and the division returns a float value. This decimal point is very important so that it doesn't crop.

With the fix provided, now you can see the expected result:

image

This fixes the issue from #303

maPer77 commented 1 year ago

Hello @edutrul, thanks for your PR.

I did some tests and it seems that the problem is solved with your change ==> "float $fontSize". I am very happy that this feature is useful for you. It was hard work to develop this, and I didn't know if I was helping anyone.

img01 img02

maPer77 commented 1 year ago

Hi @claviska, can you take a look at this PR?

afbora commented 1 year ago

@claviska 4.0.3 release doesn't include this bug-fix change.

claviska commented 1 year ago

Sorry about that. Fixed in 4.0.4.