Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

ImageDrawText UTF-8 international characters in CFImage?

New Here ,
Sep 12, 2010 Sep 12, 2010

Does the CFImage tag support Cyrillic, Japanese, and other characters using the ImageDrawText function? I have been unable to get anything but gibberish to be overlaid onto graphics when using the ImageDrawText function with a string containing international characters.

You guys outside the United States, what's the secret?

Dave

TOPICS
Advanced techniques
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Sep 12, 2010 Sep 12, 2010

I think you should save your cf-page in utf-8 encoding and enter code inside the tag cfprocessingdirective (see description), like this:

<cfprocessingdirective pageencoding="utf-8">

<cfscript>

myimage = imageNew("", 200,50);

imageSetDrawingColor(myimage, "red");

imageDrawText(myimage, "Привет = Hello!", 30,30);

</cfscript>

<cfimage source="#myimage#" action="writeToBrowser" >

</cfprocessingdirective>

Translate
Explorer ,
Sep 12, 2010 Sep 12, 2010

Yes, this function works fine with Cyrillic.

Look:

<cfscript>

myimage = imageNew("", 200,50);

imageSetDrawingColor(myimage, "red");

imageDrawText(myimage, "Привет = Hello!", 30,30);

</cfscript>

<cfimage source="#myimage#" action="writeToBrowser" >

And result:

imagedrawtest.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 12, 2010 Sep 12, 2010

Mine does not generate the same output as yours.  I copied your exact source code, but mine generated this:

_cfimg-5379833927422760034.PNG

Is there a global setting somewhere that determines what character set is used for the graphics generation or something?

Dave

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 12, 2010 Sep 12, 2010

I think you should save your cf-page in utf-8 encoding and enter code inside the tag cfprocessingdirective (see description), like this:

<cfprocessingdirective pageencoding="utf-8">

<cfscript>

myimage = imageNew("", 200,50);

imageSetDrawingColor(myimage, "red");

imageDrawText(myimage, "Привет = Hello!", 30,30);

</cfscript>

<cfimage source="#myimage#" action="writeToBrowser" >

</cfprocessingdirective>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 12, 2010 Sep 12, 2010

mojibake. you seem to have an encoding problem, can you write out the unicode

text to the page correctly? is the text in fact unicode?

you control the font used for drawing the text by passing in a font name via the

attribue collection:

imageDrawText(name,str,x,y )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 12, 2010 Sep 12, 2010

Wow, how interesting!

Apparently you cannot specify the ending tag if you use the PageEncoding parameter, but without the ending tag, it works perfectly to create the Russian text!

Without this directive, even data coming from a database will not be correctly rendered, so it doesn't have anything to do with how the string is stored in the page. Somehow the directive applies to everything done by the ImageDrawText function.  I don't believe that is documented anywhere, it it?


Thanks!

Dave

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 12, 2010 Sep 12, 2010
LATEST

OK, I was wrong about data coming from a database. It does seem to only affect literal strings.

Anyway, thanks for the help with this. The CFProcessingDirective seems to fix the problem of the string literals not being encoded correctly.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources