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!StumbleUpon!
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
admec multimedia institute - Works in joomla   2011-03-30 05:45:05
Gravatar image Hey,
I discussed it with my web development team, they agree and using dynamic font using isfr on this website, i think it is joomla based but for version i m not confirm i.e. http://www.admecindia.co.in

Thanks
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
nik - omg   2010-12-21 13:06:18
Gravatar image I've go the same problem!
aims - same   2011-08-11 12:08:07
Gravatar image I know this is quite old but I'm having the same problem and no one seems to be posting a solution?
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)
Steve   2011-01-28 23:56:55
Gravatar image Great discription, I have the same question like Lennox

Any idea how to control letter spacing?

cheers!
Remon   2011-01-30 09:50:12
Gravatar image @Steve: With True Font Family (http://www.truefontfamily.com) you can control this.
Janzell - Font-size issue   2011-01-31 07:20:44
Gravatar image Hi, Marco thanks for this script. Just wanna if there any way which I font will not be declared and it will based on the selector size?
Travis - add dynamic font-size   2011-02-04 00:41:27
Gravatar image Hi marco, really cool script, Is there anyway we can add dynamic font-size; just like what he did in his blog.
http://mushutricks.blogspot.com/2011/02/php-image-replacement-dynamic-font-size.html
Mordret - Multiple classes   2011-02-04 08:56:12
Gravatar image First of all, marco thanks for the hard work its a nice and eazy to implement code.
Question: Is there any wat to declare classes?

Example:

title1{
30px
}
title2{
20px
}
Karol B.   2011-03-19 12:04:33
Gravatar image Dude, you should check your site on Chrome, needs some serious optimization.
Greetingz!
Lexin   2011-09-19 09:08:54
Gravatar image It's a really great idea! But I had to modify it: I can get the font-color, the background-color and the font-size from 'style' attribute of replacement tag. Also, the font path for *unix like systems should be like this:
Code:
$font_file  = './Diavlo.otf' ;
ugg sale online - boots   2011-11-04 07:18:09
Gravatar image I
Anonymous   2012-01-18 09:49:42
Gravatar image <img src=hock:' /> :lol: :dry: <img src=illy:' /> :evil: :evil: <img src=illy:' />
takeyourjerseys - take your jerseys   2012-05-21 22:40:43
Gravatar image New Jersey Devils were established in 1982. Their head coach is Jacques Lemaire and their captain is in vacant. The arena is Prudential Center in Newark. New Jersey Devils Jersey are owned by Jeffrey Vanderbeek, who bought them in 2004 for $125 mil and now they are worthy $218 mil. The colors of the New Jersey Devils Jersey are red, black and white. We provide the top quality NHL Jersey in lower price. Show your support to New Jersey Devils Jersey with this gorgeous jersey."
NHL New Jersey Devils #15 Jamie Langenbrunner CCM Red and Green n
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:
 
Security Image
Please input the anti-spam code that you can read in the image.
Unsubscribe from e-mail notifications.
 
< Prev   Next >
Subscribe

Subscribe to Marcofolio