Jump to content

[SOLVED] Use any font with PHP


chordsoflife

Recommended Posts

I was just thinking (I don't know a lot of PHP) about a possible idea, at least for headers.

 

Would it be possible to type out the alphabet in a given font, caps and lowercase, spaces and special characters, then slice it and save them all as the appropriate character.jpg or something.

 

Then, write a class that explodes a given input into its individual characters, and outputs that same input in the corresponding images.

 

I would imagine that if that was possible, it would be done. So I must be missing something. Thoughts?

Link to comment
https://forums.phpfreaks.com/topic/130925-solved-use-any-font-with-php/
Share on other sites

Loading times should not be an issue actually.

 

Problem is, large font sizes[1] need to have kerning adjusted (i.e. spaces between letters). This is done on letter to letter basis, so distance between WW is different than between MW. Otherwise things start to look really ugly. A script to take care of this would not be that simple. There are also other typographic concerns.

 

 

[1]: With small font sizes lack of kerning is not as visible.

One thing I always lacked in 'handwritten' fonts is that same letters look the same... So 'a' looks always the same, so does 'b' etc... With the technique you described, you could create more than one 'picture' for each letter and then use them randomly.

You should have a look at GD fonts. Have a Google for GD font converter*, and check out http://us2.php.net/manual/en/function.imageloadfont.php.

The idea is to use the fonts to write onto an image, and then output the image. Which may or may not be suitable for what you want to do.

This may also be useful but I've not played with it yet: http://us2.php.net/manual/en/function.imagettftext.php

 

* You'll see a lot of references to a converter by a chap named Phillip, but this seems to have gone.

Well, for the most part, I got this working. There are way more variables than I originally expected though.

 

For instance, my function took two arguments: the text and the font size. I suppose I could have eliminated font size but that wouldn't make it very usable.

 

Anyway, I wound up only working with A, a, B, b, C and c, and saving each one of those at 12, 14, 16... through 38px high. Then I set up a few if/else statements to determine what size lowercase should be relative to uppercase.

 

Then I realized I would have to save 46 more characters in 14 sizes, never mind all the *(Q@#^$&*%}{:" and whatnot.

 

So yea, it worked. But no.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.