Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GD error while try load font

Tags:

php

image

fonts

gd

I try load font by imageloadfont function. When I running script I receive error:

gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully
PHP Warning:  imageloadfont(): Error reading font, invalid font header

What can cause this problem?

Env:

Ubuntu 13.04 64-bit

PHP 5.4.9-4ubuntu2.3

like image 308
Piotr Olaszewski Avatar asked Feb 01 '26 21:02

Piotr Olaszewski


2 Answers

I saw this error while trying to randomly use one of the system's .ttf file. The PHP Manual example has .gdf font file.

My image dimensions are 1013 x 638 (646294 pixels), an ID card sized image in 300 dpi.

PHP_INT_MAX in my case has a value of 2147483647 and memory limit set to 128 MB.

The converted new font file worked (.gdf format font)

Font converter: www.wedwick.com/wftopf.exe

Source: http://www.animeviews.com/article.php?ID=263

like image 78
Bimal Poudel Avatar answered Feb 04 '26 10:02

Bimal Poudel


I found the solution. The problem wasn't in the imageloadfont function.

I was trying to load the font (.ttf) to imageloadfont and set it on the image. Instead of using the imagestring function, I now used imagettftext to load the custom font and place the string on the picture.

like image 22
Piotr Olaszewski Avatar answered Feb 04 '26 10:02

Piotr Olaszewski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!