Asked 7 years ago
17 Dec 2016
Views 2349
fatso

fatso posted

imageloadfont give error in GD library

trying to load new font for imagestring to draw horizontal text in GD Library.


$string = 'abcdefg+hijk';
$fontg=imageloadfont("fontnew.gdf");
$image = @imagecreate(200, 230);
$black = imagecolorallocate($image, 0, 0, 0); //background
$white = imagecolorallocate($image, 255, 255, 255);
imagestring($image,$fontg , 1, 1,  $string, $white);
imagepng($image);
imagedestroy($image);


and it give me error

Warning: imageloadfont() [function.imageloadfont]: gd warning: one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully in imagec.php

Warning: imageloadfont() [function.imageloadfont]: Error reading font, invalid font header in imagec.php 


so what should be the issue ?
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

mostly this error arise when passed file in imageloadfont , is not proper .gdf file . you need to check again is it correct .gdf file or not ? or try to find good .gdf file and try to use it .

imageloadfont always work with proper font file.
ravi

ravi
answered Nov 30 '-1 00:00

i got same error when i try to .ttf load image font by imageloadfont .

and first i tried to solve problem by extending the memory space of php. i changed memory_limit = 128M to memory_limit = 234324 in the php.ini

but it not resolved that way

so i used function imagettftext

$white = imagecolorallocate($image, 255, 255, 255);
$font = 'font.ttf';
imagettftext($im, 20, 0, 11, 21, $white, $font, $text);


so hope it help
Post Answer