Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating an image with Image Component

Status
Not open for further replies.

5474N

Programmer
Jul 13, 2005
11
CA
Hey all,
I am trying to make a page, that submits a form to itself.
In the form is 1 text feild with a default value of "Sample".
The next field is a select box with their choice of a few fonts.
Under the form... is the image of the text in the "sample" field.
When I load the page, it works fine for maybe 3 or 4 submits, then it won't switch the font or text and therefore doesn't update the image properly.
I have to do a page refresh to get it working again.
Is it the browser cache ? can I get around that somehow ?

here is my code.

<cfdump var="#form#" />
<cfparam name="font_choice" default="" />
<cfparam name="url.action" default="" />
<!--- this is for when we start setting up for more than 1 package. right now it's set to 1 --->
<cfparam name="card_package_number" default="1" />

<cfparam name="form.text" default="Sample" />
<cfparam name="form.font_choice" default="KidScraw" />

<cfset fontstouse = "evilgeniusbb_reg,absci___,later_on,KidScraw,Georgia,Gigi" />
<cfparam name="myString" default="#form.text#"/>

<cfoutput>
<!--- form that submits and creates the new text in a new image --->
<form action="text.cfm?#session.URLToken#" name="card_text" method="post" >
<textarea cols="10" rows="2" name="text" style="text-align:center; width:100px; height:40px;">#form.text#</textarea>
<select name="font_choice">
<cfloop index="x" list="#fontstouse#">
<option name="font" value="#x#" <cfif form.font_choice eq x>Selected</cfif>>#x#</option>
</cfloop>
</select><br />
<input type="submit" />
</form>

<!--- create the object --->
<cfset myImage = CreateObject("Component","#myCFC#") />
<cfset myImage.setKey("#mySerial#") />
<!--- create some colors
<cfset color = myImage.createColor(R,G,B) />
--->
<cfset bgColor = myImage.createColor(255,255,255) />
<cfset fontColor = myImage.createColor(0,0,0) />
<!--- create fonts --->
<cfset font1 = myImage.loadTTFFile("D:\inetpub\myweeworld\includes\fonts\#form.font_choice#.ttf", 32) />
<cfset fontArray = myImage.getSystemFonts() />
<!--- create a new image --->
<cfset myImage.setBackgroundColor(bgColor) />
<!--- create an advanced string --->
<cfset advancedString = myImage.createString(myString) />
<!--- set some font and size settings --->
<cfset myImage.setStringFont(advancedString, Font1) />
<!--- set some font colors --->
<cfset myImage.setStringForeground(advancedString, fontColor) />
<!--- get the string's metrics --->
<cfset metrics = myImage.getStringMetrics(advancedString) >
<!--- create an image the width and height of the text --->
<cfset myImage.createImage(metrics.width+5, metrics.height+15) />
<!--- <cfdump var="#fontArray#" /> --->
<!--- <cfdump var="#metrics#" /> --->
<!--- draw the text into the image --->
<cfset myImage.drawString(advancedString, 0, #metrics.height#) />
<!--- output the new image --->
<cfset myImage.writeImage("D:\inetpub\myweeworld\card_creator\users\#session.username#\#card_package_number#\text_images\text.png", "png") />

<!--- Sending image to DIV --->
<script>
parent.document.getElementById("undercard").innerHTML='<img src="#url_path#card_creator/users/#session.username#/#card_package_number#/text_images/text.png" />';
</script>
<img src="#url_path#card_creator/users/#session.username#/#card_package_number#/text_images/text.png" />

<cfdump var="#form#" />
</cfoutput>


Thanks for any ideas !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top