PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 10, 2022

[FIXED] How Can I Load My Custom Font in imagestring()?

 October 10, 2022     fonts, gd, php     No comments   

Issue

My problem is Q title.

I tried http://www.php.net/manual/en/function.imageloadfont.php and: imageloadfont();

but i do not see any change and i get error:

Warning: imageloadfont(): gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully in E:\xampp\htdocs\test\texts\text01.php on line 3

Warning: imageloadfont(): Error reading font, invalid font header in E:\xampp\htdocs\test\texts\text01.php on line 3

Edit: My font.


Solution

To quote myself, you should be using imagettftext(), not imagestring().

Example usage, abbreviated/adapted from the manual page:

$im = imagecreatetruecolor(400, 30);

// Create some colors and set background to white.
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'btitr.ttf';

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im, 'path_to_file.png');
imagedestroy($im);


Answered By - timclutton
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing