Special Character in CFImage text

Posted on 2011-02-28
Last Modified: 2012-05-11
Hi all,

I'm trying to render some text (£10.00) to an image using cfimage. However I can't get the £ character to render correctly, I just get £10.00 (see attached image).

I'm using the following code to generate the image. Any help with this would be greatly appreciated.

<cfset voucherValue = "£10.00">

<!--- Create new blank image --->
<cfset newCodeImage = ImageNew("", 450, 140, "rgb", "##FFFFFF") />

<!--- Set new text attributes. --->
<cfset attr = StructNew()>
<cfset attr.font="Arial">
<cfset attr.size=110>
<cfset ImageSetDrawingColor(newCodeImage,"##000000")>
<cfset ImageSetAntialiasing(newCodeImage)>

<!--- Add value to blank image --->
<cfset ImageDrawText(newCodeImage,"#voucherValue#",0,115,attr)>

<!--- Save temp image --->
<cfimage action="writeToBrowser" source="#newCodeImage#">

Open in new window

Question by:richard-mckenna
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
LVL 52

Expert Comment

ID: 35002302
Try using the unicode representation of £
<cfset vourcherValue = "\U00A310.00">
LVL 52

Expert Comment

ID: 35002328

Author Comment

ID: 35002329
Unfortunatly not that just renders

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

LVL 52

Assisted Solution

_agx_ earned 200 total points
ID: 35002344
What version of CF are you running. It outputs fine for me w/CF9.0.1

Author Comment

ID: 35002366
Ah 9,0,0,251028 let me try updating CF. Good thinking there :)
LVL 52

Expert Comment

ID: 35002390
Try adding a UTF8 directive explicitly first. Might be the problem.

<cfprocessingdirective pageencoding="utf-8">

Accepted Solution

sajayc earned 300 total points
ID: 35002454
Try using the ascii chr code for the pound sign.

<cfset vourcherValue = chr(153) & "10.00">

Hope this helps.


Author Comment

ID: 35002492
Solved thanks guys, youve been a great help.

cfprocessingdirective didn't do anything.

After the 9.0.1 update <cfset voucherValue = "£10.00"> renders correctly.

<cfset vourcherValue = chr(163) & "10.00"> works as well (note the number is 163) and I think I'm gonna go with this as it seems a bit more complete.

Thanks again.
LVL 52

Expert Comment

ID: 35002530
cfprocessingdirective didn't do anything
Not sure why. A literal copy and pasted worked perfectly for me. But if the ascii code works, then it's definitely an encoding problem.  

Author Comment

ID: 35002589
Yeah, they also must have changed the encoding in the 9.0.1 update. Think I'll have a look at the release notes when i get chance, see if I can find anything.
LVL 52

Expert Comment

ID: 35002654
Hmm.. I just tested it again and it's not UTF8 that worked. It was windows-1252

<cfprocessingdirective pageEncoding="windows-1252">
<cfset voucherValue = "£10.00">

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Fixing some Issues with regex again 9 44
Fixing Old Legacy Code 1 52
Coldfusion - rename files in a folder 4 33
Coldfusion parsing of a cfset variable 2 44
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them ( . I did keep the main js functions but made sever…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question