• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1193
  • Last Modified:

How to convert HTML to JPG with Coldfusion (or other way)?

I need to have a way to convert a small amount of html text to a jpg, preferably using coldfusion, but if there is another way that I can use and embed successfully, that may work too.
0
monosyth
Asked:
monosyth
  • 6
  • 4
1 Solution
 
duncancummingCommented:
If you're on ColdFusion 8, you can use the <cfimage> tag to do what you need.
0
 
monosythAuthor Commented:
I am on CF8, can you point me in the right direction please for what I need?
0
 
_agx_Commented:
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
monosythAuthor Commented:
These links appear to be making thumbnails from pdfs, I will look into cfimage to see what I can do.
0
 
_agx_Commented:
Yes, but you may be misunderstanding.  They convert html to a pdf variable, then convert it to a jpg.  You can of course use cfimage, but cfimage cannot handle html.  That is why you may be better off using the technique in the links. It is far easier to handle html (<b>, <h1>, etc...) with cfdocument.
0
 
_agx_Commented:
... of course if you just want to draw plain text on an image, then yes .. you should just use cfimage.
0
 
_agx_Commented:
To answer your previous question, to draw plain text on an image use the ImageDrawText function.   Attached is a simple example, but you can also find more information about this and other image functions in the online documentation:

http://livedocs.adobe.com/coldfusion/8/htmldocs/Images_12.html
http://livedocs.adobe.com/coldfusion/8/htmldocs/Images_01.html

You might also be interested in this cfc at riaforge.cfc.  It is not text specific, but does have a few neat functions for rendering text on images:

http://imageutils.riaforge.org/




<cfset img = ImageNew("", 275, 60, "argb")>
<!--- change a few font properties --->
<cfset fontProp = { font="verdana", size="30" }>
 
<!--- draw the first word in blue text --->
<cfset ImageSetDrawingColor(img, "0000ff")>
<cfset ImageDrawText(img, "Draw", 10, 30, fontProp)>
 
<!--- draw the second word in blue text --->
<cfset ImageSetDrawingColor(img, "ff0000")>
<cfset ImageDrawText(img, "Something!", 85, 50, fontProp)>
 
<!--- show the sample image --->
<cfimage action="writeToBrowser" source="#img#">

Open in new window

0
 
monosythAuthor Commented:
I just tested that, and it would work great, actually. Is there a way to save as JPG and save to a particular file?
0
 
_agx_Commented:
Sure.  Either use the ImageWrite(..) function or the cfimage tag to save the image to disk:

<cfset img = ImageNew("", 275, 60, "argb")>
... other code
<cfset ImageDrawText(img, "Something!", 85, 50, fontProp)>
<cfset ImageWrite(img, "c:\whateverPathYouWant\theImageNameYouWant.jpg")>
0
 
monosythAuthor Commented:
This is brilliant. One more thing - can I set the background color? perhaps by drawing a square the size of the image?
0
 
_agx_Commented:
Yes. Background color is one of the parameters for the ImageNew(..) function.  Just use any hex color.

<cfset img = ImageNew([source, width, height, imageType, canvasColor])> .... ie
<cfset img = ImageNew("", 275, 60, "argb", "FFFFFF")>

http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_h-im_34.html#5179132
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now