/    Sign up×
Community /Pin to ProfileBookmark

Image Text Generator?

Hello, I Someone told me this can be down using javascript. Can anyone just give me the basic on how to make a Image Text Generator. What I mean is, like this [url]http://www.splogger.com/habbotext/[/url]

so I have a input textbox so how do I make it take that information then get the corrisponding image (a.gif b.gif c.gif etc…) then disply them.

to post a comment
JavaScript

19 Comments(s)

Copy linkTweet thisAlerts:
@NedalsJan 02.2005 — [size=1]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>untitled</title>
<script type="text/javascript">
<!--
function disp() {
text = "abcd"; // Get the text from the <input>
letters = text.split(''); // put the letters into an array
var imgStr = ""; //declare a variable for the image string <br/>
for (i in letters) { // loop though all the letters to build an image string
imgStr += '&lt;img src="' +letters[i]+ '.gif"&gt;'; // Construct the string
}
document.getElementById('name').innerHTML = imgStr; // display the images in a &lt;div id="name"&gt;
}
onload = disp;
//--&gt;
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id="name"&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
[/size]
Copy linkTweet thisAlerts:
@Pixel-ArtistauthorJan 02.2005 — [i]Originally posted by Nedals [/i]

[B][size=1]
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;&lt;head&gt;&lt;title&gt;untitled&lt;/title&gt;
&lt;script type="text/javascript"&gt;
&lt;!--
function disp() {
text = "abcd"; // Get the text from the &lt;input&gt;
letters = text.split(''); // put the letters into an array
var imgStr = ""; //declare a variable for the image string <br/>
for (i in letters) { // loop though all the letters to build an image string
imgStr += '&lt;img src="' +letters[i]+ '.gif"&gt;'; // Construct the string
}
document.getElementById('name').innerHTML = imgStr; // display the images in a &lt;div id="name"&gt;
}
onload = disp;
//--&gt;
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id="name"&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
[/size]
[/B][/QUOTE]


Yea it displays the images, but how do I get it to take the it from a input box? Besides that its perfect. ? THANKS SO MUCH!
Copy linkTweet thisAlerts:
@NedalsJan 02.2005 — Initially I intended to just give you a description of how to do this to give you an opportunity to learn but it was quicker to provide the code.

What you are asking is very easy and the solution can be found on just about any javascript post on this forum.

So I'm not going to tell you ?

However, if you really cannot figure it out, post back your attempt and I'll correct it.

BTW, you do not need to repost earlier code in your response.
Copy linkTweet thisAlerts:
@Pixel-ArtistauthorJan 02.2005 — Is this right?

<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;&lt;head&gt;&lt;title&gt;untitled&lt;/title&gt;
&lt;script type="text/javascript"&gt;
&lt;!--
function disp() {
text = form.myinput.value; // Get the text from the &lt;input&gt;
letters = text.split(''); // put the letters into an array
var imgStr = ""; //declare a variable for the image string <br/>
for (i in letters) { // loop though all the letters to build an image string
imgStr += '&lt;img src="' +letters[i]+ '.gif"&gt;'; // Construct the string
}
document.getElementById('name').innerHTML = imgStr; // display the images in a &lt;div id="name"&gt;
}
onload = disp;
//--&gt;
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id="name"&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@NedalsJan 02.2005 — Close!

text = document.formname.myinput.value;

You could also parse it into the function.

function disp(text) {...

HTML:

<button ... onclick = "return disp(document.formname.myinput.value)">

or some similar event processor.
Copy linkTweet thisAlerts:
@Pixel-ArtistauthorJan 02.2005 — I am going to try it now!

EDIT

Grrrr WTF!

<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;&lt;head&gt;&lt;title&gt;untitled&lt;/title&gt;
&lt;script type="text/javascript"&gt;
&lt;!--
function disp() {
text = document.inputbox.myinput.value; // Get the text from the &lt;input&gt;
letters = text.split(''); // put the letters into an array
var imgStr = ""; //declare a variable for the image string <br/>
for (i in letters) { // loop though all the letters to build an image string
imgStr += '&lt;img src="' +letters[i]+ '.gif"&gt;'; // Construct the string
}
document.getElementById('name').innerHTML = imgStr; // display the images in a &lt;div id="name"&gt;
}
onload = disp;
//--&gt;
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;input type="text" name="inputbox" size="20"/&gt; &lt;BUTTON TYPE=SUBMIT onclick = "return disp(document.inputbox.myinput.value)"&gt; Make Habbo Font &lt;/button&gt;

&lt;/body&gt;
&lt;/html&gt;


EDIT: Opps Kinda copied in wrong.

"document.inputbox.myinputbox" is null or not an object.
Copy linkTweet thisAlerts:
@NedalsJan 03.2005 — [size=1]
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;&lt;head&gt;&lt;title&gt;untitled&lt;/title&gt;
&lt;script type="text/javascript"&gt;
&lt;!--
function disp(text) { // parse &lt;input&gt; data
var letters = text.split(''); // put the letters into an array
var imgStr = ""; //declare a variable for the image string <br/>
for (var i in letters) { // loop though all the letters to build an image string
imgStr += '&lt;img src="' +letters[i]+ '.gif"&gt;'; // Construct the string
}
document.getElementById('name').innerHTML = imgStr; // display the images in a &lt;div id="name"&gt;
return false; <br/>
}
//--&gt;
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form name="myform" action=""&gt;
&lt;input type="text" name="myinput" size="20"&gt;&lt;br&gt; &lt;!-- that trailing / is only needed for xhtml --&gt;
&lt;input type="button" value="Make Habbo Font" onclick="return disp(document.myform.myinput.value)"&gt;
&lt;/form&gt;
&lt;div id="name"&gt;&lt;/div&gt; &lt;!-- this is needed to display the graphic text --&gt;
&lt;/body&gt;
&lt;/html&gt;
[/size]

Now that you are using an 'onclick' event, you don't need that 'onload = disp;' event

The <input> MUST have the same name ('inputbox' in your case) as you use for the function ('myinput' in your case)

Charles will probably have a go at me for the HTML construct. ?
Copy linkTweet thisAlerts:
@Pixel-ArtistauthorJan 03.2005 — THANK YOU, I am going to look more into Javascript. ?

But I obviously can't save somthing as .gif for the space. ?

EDIT: I found a way around the space.
Copy linkTweet thisAlerts:
@david2rDec 02.2008 — how did you get past the space? i can't seem to figure it out!

thank you!!!
Copy linkTweet thisAlerts:
@david2rDec 02.2008 — anybody able to help me get past the space?

thanks!
Copy linkTweet thisAlerts:
@MaydayDec 02.2008 — You may have better luck getting your questions answered if you began a new thread, rather than resurrecting a four-year old one. :eek:
Copy linkTweet thisAlerts:
@david2rDec 02.2008 — I hear you and partly agree, but there was already this content on the thread and didnt want to start all over.

If anyone can answer on this thread it would be appreciated, if not then I can start a new one.
Copy linkTweet thisAlerts:
@NedalsDec 03.2008 — But I obviously can't save somthing as .gif for the space. ?

EDIT: I found a way around the space.[/QUOTE]
I have no idea what Pixel-Artist is talking about. What are you trying to do?

If you want to get rid of any spaces that may be entered, use a RegEx to remove them, or add an alert to have the user remove them.
Copy linkTweet thisAlerts:
@david2rDec 03.2008 — I have no idea what Pixel-Artist is talking about. What are you trying to do?

If you want to get rid of any spaces that may be entered, use a RegEx to remove them, or add an alert to have the user remove them.[/QUOTE]


Hi Nedals,

Pixal-Artist in the above was asking for a script to convert text to images, and the script you provided works fine but when you enter a space (in between words like "word1 word2") it generates text to an image but as an image that can't be displayed.

Here is a test page of the script so you can see what I mean. If you enter words with spaces the "space" image is just .png (original script called for .gif) and displays a non existant image. And you can't save an image with no name to get a .png extension....sorry guess its hard to explain.

if you click this test link and type a couple words with spaces you will see what I mean.

Thank you in advance!!

http://www.myspace-compilation.com/testmscjava
Copy linkTweet thisAlerts:
@NedalsDec 03.2008 — OK.

The function disp(text) builds a string of image tags.

eg: enter 'hat', you get

<img src="h.png"><img src="a.png"><img src="t.png">

These images, saved on your server somewhere, are then displayed.

If you enter a space, it will return <img src=" .png">, but that is not a valid image.

Your choice then is to not allow spaces, or to insert some code (like 'sp') for a space and return <img src="sp.png">

Then you need to add a space img, sp.png, to your server.

While you're at it, you should also clean up your HTML.

Get rid of the...

<html><head><title>untitled</title>

Extra </head>, <body>, </body>, </html>

... midway though your code

Move the javascript into the <head> section
Copy linkTweet thisAlerts:
@david2rDec 03.2008 — ok everything you said makes sense and forgive me here cause im a novice, but what would be the code exactly for 'sp' and where would I enter it into the existing code?

thanks again Nedals, you really know your stuff!
Copy linkTweet thisAlerts:
@NedalsDec 03.2008 — Edit using this...
<i>
</i>for (var i in letters) { // loop though all the letters to build an image string
var imgname = (letters[i] &amp;&amp; letters[i]!=' ') ? letters[i] : 'sp';
imgStr += '&lt;img src="' +imgname+ '.png"&gt;'; // Construct the string
}
Copy linkTweet thisAlerts:
@david2rDec 04.2008 — Thanks Nedals, that worked perfectly! You really know your stuff. I put a credit in the script to you and your site fulspec, so when its finally pushed to production it will be there. Let me know if you have a problem with that. ?

-David
Copy linkTweet thisAlerts:
@GendeDiosJun 27.2011 — Thanks Nedals.
×

Success!

Help @Pixel-Artist spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...