Converting HTML To An Image With CF/Java
Posted By : todd sharp Posted At : April 4, 2008 1:06 PM Posted In:
18
I decided to mess around a bit with a new way to create screen captures. I know that Ray has one method for doing this, but I wanted something that would offer a little more control over the process, and could possibly work on versions of ColdFusion prior to 8. The end result of what I came up with is pretty slick I think, and it's pretty efficient as well. I'm stuck on one CF 8 dependency in the function itself (plus you'll need some method of writing the image out - but there are Open Source image packages out there). I think with some work I'll be able to overcome the internal dependency on CF 8 and make it work on prior versions. Here's how easy it is:
<cfimage action="writeToBrowser" source="#img#" />
Which produces:
You can also pass HTML directly to the method:
<html>
<head>
</head>
<body>
<div style="width:100%; height: 200px; border: 10px solid red; background:purple; color:white;">Hello World</div>
</body>
</html>
</cfsavecontent>
<cfset imgTwo = getScreenShot(html=someHtml) />
<cfimage action="writeToBrowser" source="#imgTwo#" />
Which produces:

I'm not quite ready to release the code - still have a bit of clean up to do on it. What do folks think? Is this useful?



-Brian
Please let me know when you are ready to release.
I'd be very interested in checking out the code you use from Java to be able to invoke IE to do you bidding.
Can you take shots of the page beyond the size of the browser? That is, if the page scrolls, can you snap the entire page, or just the visible portion?
Still working on it Danilo, but that is my plan....
Very cool stuff.
-Brian
I guess I was talking to Todd Sharp. I've seen IE used to help with screenshots of web pages, so I assumed that that was what being done, invoking IE from within Java. I had started my post right after your original post, but got busy and didn't submit until later and so I missed the post about it being in pure Java.
@Todd Sharp,
If the rendering is acceptable, then that would be good for what I've been working on lately. I did notice that the snap shot you posted doesn't show your menu bar, is that due to the specific page you snapped, or due to the rendering within Java/CF?
http://webthumb.bluga.net/home
Works quite well! Cheap too..
http://cfsilence.com/blog/client/index.cfm/2008/4/...
I was a bit dissapointed in the results when fetching remote content, but for simple html to image it seems to work good...In fact, it's what I use to generate the thumbnails on http://slidesix.com
PS - what's up with using Google suggest for your URL?
PSS - any plans on sharing your code/experiences with your approach to HTML-image with Java?
<cfset container.setSize(contentWidth,contentHeight) />
But GREAT WORK! Dan
<cfloop condition="#stormBase.getViewPortState("hello")# NEQ 'ready'">
<cfdump var="#stormBase.getViewPortState("hello")#"></br>
<cfset sleep(100) />
</cfloop>