Dynamic PHP Font Generator

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

This entry was posted in Featured Content, PHP and tagged , , . Bookmark the permalink.

25 Responses to Dynamic PHP Font Generator

  1. Tom says:

    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!

    • Ryan Maffit says:

      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…

  2. Hebee says:

    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

  3. ElenaLisvato says:

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

  4. Simphax says:

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

    • Ryan Maffit says:

      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 :)

  5. Wietse says:

    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.

  6. Fifty says:

    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!

    • Ryan Maffit says:

      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,
      	)
      );
  7. Fifty says:

    Thanks appreciate it, I was missing the comma.

  8. 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

  9. Clint says:

    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

  10. Pingback: Corriger le plugin TTF Titles sous PHP 5.2.10+ « Globe Design Studio

  11. Pingback: Correct TTF Titles plugin under PHP 5.2.10+ « Globe Design Studio

  12. Pingback: test « Globe Design Studio

  13. Pingback: hello world « Globe Design Studio

  14. Pingback: Corriger le plugin TTF Titles sous PHP 5.2.10+

  15. a really good read by you looking forward to come back more very soon.

  16. Schedule says:

    Best you could edit the page name title Dynamic PHP Font Generator | Ryan Maffit to more suited for your webpage you create. I liked the blog post withal.

  17. rob says:

    If anyone is having trouble with the image getting cut off, make sure you remember to delete the contents of the cache folder before refreshing in the browser! ;)

  18. Thank you for every other great post. Where else could anyone get that type of information in such a perfect way of writing? I have a presentation next week, and I’m on the look for such info.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

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