Jump to content

Recommended Posts

Hello

 

i just learned how to use .ttf fonts on a webpage ,but i noticed that IE Browsers arent supporting it

so i thought to make add the Fonted Text into a image so IE Browsers will see the font in a image and not a replaced font text

 

Could someone please provide me a Simple Script to make a PNG image with the text and font and a invisible background ?

 

 

Link to comment
https://forums.phpfreaks.com/topic/211942-create-image-from-text/
Share on other sites

As an aside...

 

If you want to use fonts in the webpage w/o resorting to graphics, take a look here...

 

http://www.cre8ivecommando.com/the-best-way-to-embed-a-font-in-your-website-2025/

 

I use it here http://the-gypsy-king.com/

image.php

<?php

// Set the content-type
header('Content-type: image/png');

$text = (isset($_GET['text'])) ? $_GET['text'] : exit();

$font = 'A.C.M.E._Explosive_Bold.ttf';  //location of your true type font.

// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

 

test.html

<img src="image.php?text=This_is_a_test" alt="test" />

 

Tell us how it goes.

 

Make sure your font file exists, and has no spaces in it.

Killer...

I tested the link I gave (the tutorial), it works fine no errors. Soooo we need to see your code

 

I think he either has a space in his font file name, or his font file doesn't exist.  I tried duplicating his error, and that was the only two ways I could get it to return that error.

Saying "it contains errors" isn't particularly useful to anyone trying to help you. What errors specifically, are you getting?

 

alex.. the error is the one you usually get on a php image

 

The image “http://localhost/Font%20Test/test.php” cannot be displayed, because it contains errors.

 

thats what it says if i use the first example from paul s url

 

ohhhhhhhh thank you bones ...

the scripts seemd to be working ... the reason i was getting that error was because my font file had spaces

 

i will play with it and  reply if i need further support :)

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.