Placed in: Home
Use a custom font on your website

Webdesigners always have to make sure that they use a common font for their website, otherwise it'll display incorrect on browser that don't have the font installed. This can be really annoying if you want to use a nice custom font. You could load the font in Photoshop and save it as an image, but this isn't dynamic and is not SEO. Here are two solutions on how to make dynamic custom fonts.

This is a dynamic custom font

Using image replacement

And is SEO proof

The font used above is called Diavlo and uses PHP Image Replacement. The other technique that you can use is sIFR. These can very good be used as attractive blog titles.

PHP Image Replacement

Original story at dezinerfolio.com

As you could see above, the dynamic text are all images. It uses PHP and JavaScript that replaces all the content in specified tags with images. For example, the dynamic tekst above uses the following code:

<script type="text/JavaScript" src="ifr.js"></script>
<h2 class="title">This is a dynamic custom font</h2>

It's as easy as that. Now your browser will display the custom font correct, while the code will stay intact. This is important for SEO.

Customize

You can customize the files to your own needs.

ifr.js

replaceSelector(".title","ifr.php",true);
var testURL = "test.png" ;
  1. .title - Tag (or Class) that will be replaced with images
  2. ifr.php - Location of the PHP file that generates the images
  3. true - Enable / Disable line breaks (Splits each word into an image so it can float)
  4. test.png - Location of the test image

ifr.php

$font_file  = 'Diavlo.otf';
$font_size  = 30 ;
$font_color = '#000000' ;
$background_color = '#ffffff' ;
$transparent_background  = true ;

Change these values to your needs. Take note that the font_file is capital sensitive.

Upload all files to your PHP host and open index.php. You should now be able to see the custom font displayed as images.

Attached files:

SourceDownload Source

DemoView Demo

sIFR (Flash)

The PHP Image Replacement works fine and is easy to install, but if you want more options (Selecting & copying the text, linking the replacement with an URL), you should take a look at sIFR. This works with Flash and doesn't need a PHP server.

Importing sIFR is a little bit harder than the PHP Image Replacement. First, import the correct files (JavaScript and CSS).

<link rel="stylesheet" href="sIFR-screen.css" type="text/css" media="screen" />
<script src="sifr.js" type="text/javascript"></script>
<script src="sifr-addons.js" type="text/javascript"></script>

Now put the CDATA at the bottom of your page, just before the </BODY> tag. You can customize this code to your own needs (Other font, color, size etc.), just make sure you read the documentation that you can find in the source.

<script type="text/javascript">
//<![CDATA[
if(typeof sIFR == "function")
{
sIFR.replaceElement("h2", "diavlo.swf", "#000000", null, null, null, 0, 0, 0, 0);
};
//]]>
</script>

Now all the things placed in a H2 tag will be replaced with the information found in the Flash (.SWF) file.

Attached files:

SourceDownload Source

DemoView Demo

One final note: Don't use any of the above techniques to fully display your website in a custom font. It'll make your server slow due to heavy load and your readers will not like it. Good luck.


Tags:  custom font webdesign internet blog

Interested in this topic? You might enjoy another article I've written called

Did you like this article? Subscribe to my feed or email to keep updated on new articles.

Spread the word and submit to:
Digg!Reddit!Del.icio.us!Facebook!Technorati!StumbleUpon!Newsvine!Furl!Ma.gnolia!
Comments
Add NewSearchRSS
rubot   2008-02-21 01:51:19
Gravatar image is it possible to use the ifr technique in joomla 1.5? the sifr worx without problems.hhmpf:)
i tried it, but think i´m too stupid:(, maybe you have a hint wheather to include the ifr.php or something?
thx very much
Marco   2008-02-21 10:10:43
Gravatar image Hi,

The ifr is not for Joomla! 1.0.x or J! 1.5. Maybe I'll create a plugin for them later.

Greetings,,,
Ryan   2009-10-03 21:24:28
Gravatar image Hey. Of your trying to do fonts in Joomla try http://fontmeup.com
dzogchen - Question   2008-03-17 13:30:22
Gravatar image This is a very useful gadget for it's simplicity and functionality. But I'm having a problem with accentuated letters like á à ê.. etc..., I've searched for info about how to bypass this problem but didn't found anything, is there any info about this anywhere?

Thank you so much,
dz
Marco - What do you use?   2008-03-17 18:26:53
Gravatar image What are you using? The sIFR or PHP Image Replacement?

And are you sure the "special characters" are supported by the font file?
dzogchen   2008-03-17 18:52:07
Gravatar image I'm using the PHP Image Replacement, and yes, on Photoshop I can make accents with this font.
I'm using charset UTF-8 on the html.

dz
GlamisPsd - Hyerlinks don't work using this   2008-05-09 23:42:06
Gravatar image Marco, this is a great tool. One question, got it to work for text but does not work if trying to use it for a link button. See code below. What am I doing wrong here?

The minute I use the class, link does not work.

"Sand Sports One Test of the wrap

Help is appreciated.
Mutasim - Stylized Fonts?   2008-09-21 17:30:43
Gravatar image Hey, is there anyway of applying a black stroke around the outline of each character and gradient of 2 colors?

I'm assuming if a duplicate of each character (increased in size by 103% or something) is rendered behind the other character, then it should act as the border.

Not sure about gradient though :(

Cheers,

Mutasim
Mutasim - Gradient   2008-09-21 17:51:05
Gravatar image I found some work on gradient in GD, I managed to make a square with two color gradient. Not sure if you could implement this into color of font.

http://planetozh.com/blog/my-projects/images-php-gd-gradient-fill/
Yordan Milenkov - Cyrillic alphabet   2008-10-02 11:35:17
Gravatar image Hi

I try to use this nice piece of code with cyrillic alphabet, but in result only image placeholders.

Is there a solution for using it with cyrillic alphabet?

Thanks in advance!
Remon Lammers - Another alternative   2008-11-13 12:31:50
Gravatar image Hi,

I developped something similar, only with no configuration what so ever. Just drop the files in a directory, truely add one line of script and you're set. No need to configure anything else or initiate it.

It works on almost all browsers, even old ones. It was developed to respect standards and is completely driven by CSS. There is a free version and a professional version. The pro version has full support for @font-face.

Check it out if you like. It's called True Font Family and the website is http://www.truefontfamily.com/
John - IE7 issue   2008-12-10 14:18:37
Gravatar image Hi,

The PHP replacement looks fine in Safari and FF but in IE7 the image is always large, it's as though the Font Size attribute is being ignored. Am I missing something?
John - IE7 Issue   2008-12-10 14:33:45
Gravatar image It seems that IE7 (or at least my version!) only replaced the first word, if I urlendode the text then it works fine.
Norm - Almost there!   2009-03-03 11:42:04
Gravatar image I have implemented your code, and I'm certain it's almost working... I think its just paths that are the problem. I've made it work in with a custom template within Joomla 1.5

When I look at the code via firebug, all the code appears to be rendering, except the actual image. any ideas?
URL = design.netreach.com.au/saltphotography

Cheers
Derek - Webmaster   2009-03-18 02:54:04
Gravatar image How do i get this to work without there being the white background?
Marco - Which technique?   2009-03-18 08:47:47
Gravatar image Which technique are you using? Images or flash?
Derek   2009-03-18 10:33:01
Gravatar image im using flash
Marco - New version   2009-03-18 13:29:29
Gravatar image Download the new version of sIFR and check the new API. You should be able to set the background colour to "transparent" in that version.

Good luck!
Derek - new version   2009-03-18 19:30:39
Gravatar image sounds good. where can i get the latest version?
Marco - Here ya go:   2009-03-18 22:05:01
Gravatar image Here ya go:
http://wiki.novemberborn.net/sifr3/

Good luck!
Chris   2009-03-22 10:02:50
Gravatar image Does the font file need to be in the root folder of the server? Thanks!
Noctis - Accents problem corrected   2009-03-25 20:55:54
Gravatar image I modified a line in ifr.js, in "replacement" function...

var url = items[i].url + "?text="+(tokens[k]+'%20')+"&selector="+escape(items[i].selector);

JS is no longer encoding accents, so it works fine for me.

I hope this helps!
Vinnie   2009-07-29 07:18:43
Gravatar image Hi Noctis ,

I've just replaced the line you mentioned before but still not working. Did it really work for you?

The curious is that I have the script working pretty good with accents when in localhost. When I run it online the letters with accents are converted in white boxes. So it makes me think that is more a server side issue than the script issue. Any help would be really appreciated.
Derek - true type font file   2009-04-13 22:44:14
Gravatar image hey marco, im goin with php instead if flash. question is, will this work with true type font files? or only open type?
Marco - Don't know   2009-04-16 07:44:56
Gravatar image Personally, I don't really know. I assume that both should work, but I'm not sure.

Simply try it out to see if TTF files work!
Derek - test image   2009-04-16 22:28:03
Gravatar image Ok I'll try the TTF file. Just one other question, what is the purpose of the "test.png - Location of the test image ". What exactly is this file doing? I opened it up in photoshop and it's jus a 1x1 white box.
Derek - links   2009-04-17 02:43:48
Gravatar image Ignore my last post. I realised what I asked after and it clicked. One thing I can't get to work is making the text a link. Any ideas?
George B - Linking via Wrapping   2010-01-16 01:05:05
Gravatar image Wrap your element that you're going to be changing into an image inside another element.

Code:
[/code]

This will allow the image to be linkable ... the next issue is the border around your images. Use CSS to change your element to
[code].class img { border: none }
Gianni - wrapping?   2010-05-15 08:31:33
Gravatar image what do you mean by wrapping?

i tried some divs but it doesn't work
Anonymous   2010-05-15 17:34:23
Gravatar image By "wrap" I mean in another tag such as a DIV or P tag. Then used your HREF around that "wrap" tag.

Essentially you will be linking the entire DIV around the font images.
Derek - php image n links   2009-04-21 01:56:05
Gravatar image does any one know how to make the images smaller and how to hyperlink them?
Samantha Gale - Wordpress   2009-07-11 16:12:46
Gravatar image Has anyone had this working within wordpress?

Inside header.php


Inside page.php
This is a dynamic custom font

I've also tried putting the last line into the body part of the header file with no luck - please help!

Thanks
George B - Wordpress Mod_Rewrite   2010-01-16 00:55:30
Gravatar image It seems that Mod Rewrite is messing with the production of a font replacement even though the source has included it. If you have pretty URLs on in Wordpress then IFR only works on the main page (index.php)...

any thoughts on this?
touristic - Image broken   2009-08-17 15:08:55
Gravatar image Hello,
Thank you for this usefull an excellent plug in!
I'm developping a new site and everything was ok until today. Images are not shown correctly, in your website too (for exemple, "dynamic", I can't see the lower part of y, both in IE and FF).
Are there a problem? Thanks for your answer!
Lennox B - Mr.   2010-01-30 06:47:23
Gravatar image This script is great. I'm curious if there is anyway to adjust the spacing between the letters (i.e. css letter-spacing). Any one have a fix or suggestion?
Anonymous   2010-06-09 11:49:08
Gravatar image :P :unsure: :woohoo: :huh: :whistle: :!: :?: :idea: <img src=hock:' /> <img src=hock:' /> :X <img src=ide:' /> :arrow: :idea: :angry: :0 :cheer: B)
Read more...
Name:
Email:
  Gravatar enabled.
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Unsubscribe from e-mail notifications.
 
< Prev   Next >
Subscribe

Subscribe to Marcofolio