Link to home
Start Free TrialLog in
Avatar of monosyth
monosythFlag for United States of America

asked on

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.
Avatar of duncancumming
duncancumming
Flag of United Kingdom of Great Britain and Northern Ireland image

If you're on ColdFusion 8, you can use the <cfimage> tag to do what you need.
Avatar of monosyth

ASKER

I am on CF8, can you point me in the right direction please for what I need?
Avatar of _agx_
These links appear to be making thumbnails from pdfs, I will look into cfimage to see what I can do.
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.
... of course if you just want to draw plain text on an image, then yes .. you should just use cfimage.
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I just tested that, and it would work great, actually. Is there a way to save as JPG and save to a particular file?
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")>
This is brilliant. One more thing - can I set the background color? perhaps by drawing a square the size of the image?
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