Jump to content

[SOLVED] Text to Image


PhaZZed

Recommended Posts

Greetings,

 

I am curious about text to image encoding - I have had a look at phpclasses.org and have managed to download a library and convert some text to an image in png format - this is all working, but what I would really like to do is attempt to code one of these 'glitter text' things. In other words, the user would enter in their name and it would display their name in 'funky colourful' text.

 

I've seen it done all over myspace and facebook, and just wonder how this works or if anyone has some sample code. There is a much bigger picture to this, I don't want to create a silly kids text converter, but I need the understanding before I can evolve.

 

Any help will be appreciated. Thank-you!

Link to comment
Share on other sites

you'd want, somewhere along the lines of:

 

<?

$font = "funky_colourful.ttf"; //assuming it's in the same directory.  If you want to give the user a choice of fonts, I'll tell you how to do that seperately if you so request.

$red = ImageColorAllocate($image, 255, 0, 0); // Red

$user = $_POST['username'];
$text = $_POST['usertext']; // The text that'll be on the image

//$image = ImageCreate(100,80); 
$image = ImageCreateFromPng("filename.png"); // Assuming you want to add the text to a pre-designed background, or whatever.

$blue = ImageColorAllocate($image, 200, 200, 255); // prepare some blueness

ImageFill($image, 0, 0, $blue); // fill the canvas

imagettftext($image,10,0,10,10,$color,$font,$text); //  

header("Content-Type: image/png"); // tell the browser what we're gonna give it
ImagePng($image); // paint the image in browser
ImagePng($image, $user.".png"); //export as png file
ImageDestroy($image); // clean up resources

?>

 

Sam

 

Link to comment
Share on other sites

That's fantastic helrazor!!!

 

I got it running with a different font, and changing background colours, etc. I'm pretty well rehearsed in PHP so I can go wild from here! Just need to find out what each function does, so I can change the font size. I can write the code to change fonts, etc. that's easy :)

 

Thanks a million and one!

 

 

Link to comment
Share on other sites

I actually dropped you an email..

 

Hey bud,

 

Thanks a million for the help with the text to image on phpfreaks

forums. I looked high and low for something like that, big up!

 

http://www.sparklee.com/

 

That is an example of what I would like to acheive, I've managed to

solve the font sizes and positioning, it's not the filling that might

be tricky..

 

1. create coloured background full of stars

2. print font on top

3. switch layers

 

almost like that i suppose...

Link to comment
Share on other sites

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.