Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-04-09
11
Medium Priority
?
1,155 Views
Last Modified: 2012-05-06
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
Comment
Question by:monosyth
[X]
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
11 Comments
 
LVL 16

Expert Comment

by:duncancumming
ID: 24109650
If you're on ColdFusion 8, you can use the <cfimage> tag to do what you need.
0
 

Author Comment

by:monosyth
ID: 24109664
I am on CF8, can you point me in the right direction please for what I need?
0
 
LVL 52

Expert Comment

by:_agx_
ID: 24109729
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:monosyth
ID: 24109895
These links appear to be making thumbnails from pdfs, I will look into cfimage to see what I can do.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 24109954
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
 
LVL 52

Expert Comment

by:_agx_
ID: 24109962
... of course if you just want to draw plain text on an image, then yes .. you should just use cfimage.
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 24110666
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
 

Author Comment

by:monosyth
ID: 24110737
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
 
LVL 52

Expert Comment

by:_agx_
ID: 24110856
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
 

Author Comment

by:monosyth
ID: 24111627
This is brilliant. One more thing - can I set the background color? perhaps by drawing a square the size of the image?
0
 
LVL 52

Expert Comment

by:_agx_
ID: 24111684
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

Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Suggested Courses

688 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