Filed under: Featured Content, PHP

Dynamic PHP Font Generator

by Ryan Maffit on Jun 5th, 2009

Tags Share Comments (19)

This is a little script I expanded upon that I found from one of my previous clients. The original script was created by Stewart Rosenberger. The WP Now website uses this script to dynamically generate testimonial signatures.

Dynamic PHP Font Generator Version 1.0

Related Articles
Leave a Comment »19 Comments
  • Reply » Tom June 23, 2009

    Great script!

    However, it appears that the text gets cut off at the bottom when it is being generated on a server running PHP version 5.2.10. All older versions of PHP run this script flawlessly. Do you know why this script may be malfunctioning on version 5.2.10? Here’s an example of what the created .png image looks like on a version 5.2.10 server:

    http://cortello.com/dev/font.php?preset=testimonials&text=hello

    Thank you!

    • Reply » Ryan Maffit June 23, 2009

      Hey Tom,

      Give this a try:
      On line 151 where it says
      “$height = ImageFontHeight(5) + 10;”
      Change it to something like
      “$height = ImageFontHeight(5) + 15;”

      I’m not really sure why PHP 5.2.10 does this, maybe they changed something in the way it calculates the height…

  • Reply » Hebee July 15, 2009

    Hi Ryan,

    I follow your step, however, the title didn’t change anything at all.
    Is there anyway that we can upgrade this program which fit PHP 5.2.10?

    Thanks,
    Hebee

  • Reply » ElenaLisvato August 4, 2009

    Hi, I can’t understand how to add your site in my rss reader. Can you Help me, please :)

  • Reply » Simphax August 15, 2009

    Hello! In what licence is this code distributed? I would like to add this function as an add-on for Concrete5

    • Reply » Ryan Maffit August 15, 2009

      Well, I found the script a few years ago and had to use it for a recent project of mine but it appears the original author’s website link does not work any more so I am not sure what license it was originally released under. I did a bit of research and found http://www.artypapers.com/csshelppile/pcdtr/ but the download link appears to be inactive… I personally don’t mind what you use it for :)

  • Reply » Wietse August 25, 2009

    I had the same problem: the text got cut off at the bottom. To solve this problem I modified the php file as follows.
    $dip = get_dip($font_file,$font_size) ;
    change to:
    $dip = get_dip($font_file,$font_size)+7 ;
    The addition probably depends on the font and fontsize you’re using.

  • Reply » Fifty August 27, 2009

    Excellent script. How would you add more than one preset?

    Would that be multiple arrays?

    hd is arial then hd2 is helvetica.

    $presets = array(
    ‘hd’ => array(
    ‘font’ => ‘arial.ttf’,
    ’size’ => ‘18′,
    ‘font_color’ => ‘8e1901′,
    ‘bg_color’ => ‘ffffff’,
    ‘transparent_background’ => true,
    )
    );
    $presets = array(
    ‘hd2′ => array(
    ‘font’ => ‘helvetica.ttf’,
    ’size’ => ‘18′,
    ‘font_color’ => ‘8e1901′,
    ‘bg_color’ => ‘ffffff’,
    ‘transparent_background’ => true,
    )
    );

    Thanks!

    • Reply » Ryan Maffit August 27, 2009

      You would need to add the other preset as another item in the main $presets array, like this:

      $presets = array(
      	'hd' => array(
      		'font'	=>	'arial.ttf',
      		'size'	=>	'18',
      		'font_color'	=>	'8e1901',
      		'bg_color'	=>	'ffffff',
      		'transparent_background'	=>	true,
      	),
      	'hd2' => array(
      		'font'	=>	'helvetica.ttf',
      		'size'	=>	'18',
      		'font_color'	=>	'8e1901',
      		'bg_color'	=>	'ffffff',
      		'transparent_background'	=>	true,
      	)
      );
  • Reply » Fifty August 27, 2009

    Thanks appreciate it, I was missing the comma.

  • Reply » Fernando FIlipe September 10, 2009

    Hey guys, im having the same croped text error as Hebee. My blog site has an example of what is happening with the text.

    If I dont specifiy the font and let PHP use its default it works fine.

    Editing the $dip line to +7 works in Firefox but not in IE … ??

    Any suggestions ? I have tried different font files and try forcing it to draw the box bigger, but none of those changes change anything.

    Your help is appreciated.

    THanks
    Fernando

  • Reply » Clint September 22, 2009

    Fernando,

    It works in IE for me, but you might have to delete your temporary files, or change the text to see it work. I am in IE 8, however.

    -Clint

    • Reply » Fernando Filipe September 24, 2009

      Clint,
      Thanks for that mate… i dont know what I am doing but it definitely isn’t working for me.. I may have to start from scratch again.

      Fernando

  • [...] téléchargement du Plugin Sources utilisées pour cet article : Page du référencement du bug Page d’un générateur php de police Cliquer ici pour annuler la [...]

  • [...] page of the Plugin Sources used for this article : Page of the referencing of the bug Page of a php generator php of font Cliquer ici pour annuler la [...]

  • [...] page of the Plugin Sources used for this article : Page of the referencing of the bug Page of a php generator php of font Cliquer ici pour annuler la [...]

  • [...] page of the Plugin Sources used for this article : Page of the referencing of the bug Page of a php generator php of font Cliquer ici pour annuler la [...]

Get a GravatarLeave a Reply

Name: « Required

Email Address: « Required

Website URL: « Optional

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">