We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon\Image\Adapter\Gd throwing an exception for the text function

I have the following in my code:

use Phalcon\Image\Adapter\GD as Image;
...
    $imagePath = BASE_DIR . '/public/img/map-icons/' . $client->getId() . '/' . $file;
    $image = new Image($imagePath);
...
    $fontFile = $this->getFontPath();
    $image->text($text, $x, $y, 1, '#FFFFFF', $fontSize, $fontFile);

Under Phalcon 1.3.4 and php 5.4.45 it works fine, but when I migrated the application to a new server running Phalcon version 3.4.5 and php 7.3.17 the $image->text($text, $x, $y, 1, '#FFFFFF', $fontSize, $fontFile); is giving the following error:

Project staging.api.my-domain.com raised exception class Phalcon\lmage\Exception with message "Call to imagettfbboxO failed" at gd.zep, line 357

The literal values being passed to $image->text(..) are as follows:

$image->text(H, 9, 20, 1, '#FFFFFF', 11, '/var/www/vhosts/staging.api.mydomain.com/src/fonts/arialbd.ttf');

I have googled high and low but have found no mention of this error.

What could be causing this?

Can anyone help me?

Thanks, Nick

edited Oct '20

When I try the example for imagettfbbox given on the page here https://www.php.net/manual/en/function.imagettfbbox.php the emaple works and shows diagonal text in a white box, so I don't think there is an issue with imagettfbbox. However, the parameters shown for imagettfbbox in the php manual are as follows: imagettfbbox ( float $size , float $angle , string $fontfile , string $text ), but for phalcon gd text() they are text (mixed $text, [mixed $offsetX], [mixed $offsetY], [mixed $opacity], [mixed $color], [mixed $size], [mixed $fontfile]). Could it be that gd text() is using imagettfbbox incorrectly for Phalcon 3.4.5?

I have also asked on StackOverflow here https://stackoverflow.com/questions/64541937/phalcon-image-adapter-gd-throwing-an-exception-for-the-text-function



205
Accepted
answer

This is a bug but won't be fixed in v3.4.5: https://github.com/phalcon/cphalcon/issues/15188

edited Dec '20

Phalcon\Image\Adapter\Gd throwing an exception for the text function ... https://www.php.net/manual/en/function.imagettfbbox. Phalcon\Image\Adapters\Gd utilizes the GD PHP extension. In order for you to If any of the parameters are not correct, a Phalcon\Image\Exception will be thrown. text(). You can add text to your image by calling text() . The available the image */ public function mask(AdapterInterface $watermark);

official website