Someone on CF-Talk posted a really cool little executable that can make thumbnails of a web site page if given a URL. I set up a little demo of it so people can see how it works. The demo uses ColdFusion and CFExecute to create the thumbnail. You can see it in action and download the ColdFusion code.
Check it out: http://www.bennadel.com/resources/demo/3/
The executable, WebShot, was created by http://www.websitescreenshots.com/
It's not perfect, but it's pretty darn cool.
Looking For A New Job?
- 7 Year Lead Programmer with MSSQL expertise to assist in live website at Atprime Media Services
- .Net Developer at LendingUSA
- ColdFusion Application Developer / Portland Oregon at DealerPeak
- Web Applications Developer at University of California, Davis
So that's how it's done...
I've been wondering how this is done.
don't mind the redundant sentences... I'm still not entirely with it today ;)
It's done using a command-line executable. You can check out the demo and see it in action. If you want to look at the code, check it out at:
and the executable is available at:
[EXE No longer available] http://www.bennadel.com/resources/demo/3/webshotcmd.exe
As far as how the executable actually goes and takes the screen shot? I am not sure. You would have to check on the developer's web site. I think it is done using Internet Explorer. But anything beyond that is more than I can answer.
Each time I read your code I surprised with nice, wonderful, and some vague ColdFusion coding tips, which is make me feel that I am unskilled freshman and not an expert ;-) as I WAS think :( . So, here is in cfm file above, I find the following:
- calling Trim and ReplaceAll functions in this way:
strArgs.Trim().ReplaceAll( 'xxxxxx', ' ' )
which is like Java and C function call, whose assumes that strArgs variable is String Object and we are calling the functions/methods of that Object Class. For me It is new and first time I know that. Another thing is, ReplaceAll function is not documented in coldfusion documentation but it works fine even with CFMX6, so I don't know how and where can we find other undocumented functions resource.
- Second is cfcatch after cfparam, as I know, cfparam will not throw any error if the paramed variable is not exists.
- Third, can you just write a brief note of what can I do - not how to do - with cfcontent tag.
Sorry if my examples are vague. My primary goal here is spread information so I will try to make my examples clearer. In some cases though, I am just touching upon things that I have already touched upon so my explanation will not be as clear. Please do not feel like a freshmen, that is certainly not my goal.
As far as calling Java string methods on the string method, this IS undocumented as far as I know. However, in ColdFusion, simple objects are stored as strings while they are "typeless." Please check out this post about it:
... and here is the post in which I went back and forth with Ben Forta concerning this sort of thing:
Remember, ColdFusion is built on top of Java. Each of the objects in ColdFusion is actually a Java object underneath. While it is not documented, you can call Java methods of that object directly. From what Ben Forta says, the string methods will never go away. However, calling Java methods directly on something like a query object is not set in stone and might change in the next generation of ColdFusion releases. So, you have to go that route at your own risk.
As far as the CFTry / CFCatch / CFParam, I am using it to catch errors when the value FORM.submitted is NOT numeric. If you look at the param tag, I am paraming the FORM.submitted value to type NUMERIC. That means that if the form somehow submits a value that is non-numeric (ex. 'a', '') then the CFParam tag will throw an error because it's like "Wait a minute punk, this is no numeric value!". The CFCatch tag catches that error and then just sets the form value of submitted to zero.
Now, how would the submitted value not be non-numeric? Someone would have to hack the form somehow... which is not going to happen unless someone was trying to break the form some how... but I would suggest getting into the habbit of paraming in this style. That way you never have to worry about errors getting by that you didn't handle.
So, for the CFContent tag, it can do more than I ever do with it, but basically it can do the following:
- Reset the output buffer (reset=true attribute). What this basically does is clear any non-flushed content so that nothing before the CFContent tag will ever be outputted to the web browser. I use this so that all the pre-page-processing white space is erased from the source getting sent to browse.r
- Tell the browser what type of content is coming to it (ex. type=text/html). So, if you wanted to send something like plain text instead of HTML you could send type="text/plain". The browser would then NOT interprut the page as HTML, but instead plain text.
- In addition to type, you can also use CFContent to stream content to the browser. You can stream a file via the file attribute. This will stream the content of the given file to the browser. You could use this sort of feature to stream files that are securely placed outside of web-accessible areas of the site. You could also use this to stream dynamically created files. For example if you created a CSV file on the fly, you could save it to a temp file and then stream it to the browser via CFContent.
Then, once you stream the file, you can opt to delete the file after the streaming is done via the deletefile=true attribute. This will stream the file to the user, then delete it once it is done.
- Finally, there is a "variable" attribute which does the same thing as the file attribute, but I don't think it is available in CFMX 6, but not sure.
Now, remember, you can only tell the browser about the content once. If some of the output stream makes it the browser, you can no longer call and CFContent or CFHeader tags.
I hope this has been helpful. And remember, please ask me any questions. I hate to think that any of this is more confusing than it is helpful.
I don't mean that all your examples are vague; contrary all are clear and understandable for the most but may be sometimes not for me, and this is my fault. You shouldn't be sorry because actually I meant that sometimes your code contains lines which are I don't know how and why it is written like that, and I just need some explanation for that to understand. So, I should ask.
I almost understand the functions CFContent tag can do. Now I need to try and apply it so I can fully understand. The main problem for me is that I'm not using the power of ColdFusion, I use the main tags and instructions that are the fundamentals of all programming language, like (cfquery, cfoutput, cfset, cfloop, cfswitch, cfif ...) and bypass all other important and powerful features believing that I am a programmer. But from now on, I'll try to know and use whatever ColdFusion tags and features I can. Believe me your posts are fully helpful.
Ben, Really I thank you and appreciate all yours.
I am always glad to help. If you are ever unclear as to how something works, please ask me. I can always set up a Demo for what ever situation you are in. I can write some sample code and comment it up the wazoo so you can really see line-by-line why I am doing things.
Just remember, for every question you ask, dozens of other people are thinking the same thing but just not asking about it.
You give me a great PUSH, I need your advice but I was thinking that I'm disturbing you. I Hobe that I'm not.
I had read the post about your certificate - by the way, congratulation - you said " To prepare for the exam I read Ben Forta's exam guide " do you mean this book
? If it is not, which one is it?
Notice that I'm not preparing for exam, which book you advise to learn and master ColdFusion?
FINAL, How to add link to the post.
Yeah, that is the book I used for exam prep. It is good for exam prep, but if you are not getting ready for the test, I would not suggest it. It does not go into a lot of depth. I basically covers the surface of all the features of ColdFusion. There is a lot that is left unexplained.
If you just want a good book to really learn the ins and outs of ColdFusion, one of the great books that I have read it the ColdFusion MX Bible. You can search for it on Amazon (my post linking is not working so great). It was published when MX 6 was out, so it is not going to have MX 7 stuff in it. But, a lot of 6 is still very great.
Now, realize that it is a text book. Not a super fun read and its like 1100 pages or something crazy. But if you want something nice and thurough, I would highly recommend it.
I have heard good things about ColdFusion WACK (i think it stands for web app construction kit or something) but cannot vouch for it myself.
On top of that, I am someone who just learns well from testing stuff out. Write lots of code. Experiment. Doesn't have to be applications, just a snippet here and there and it really starts to sink in.
Your last question about how to add links to the post? I am not sure exactly what you mean. I think maybe you mean how to auto-link text links in the post... clearly mine is not working so well. I think i am gonna change it from auto linking to the kindof stuff you see on message boards like
[url href://www.bennadel.colm]link text goes here[/url]
Not really sure yet... the blog is still young.
Check out Thumbnailspro.com, they are FREE while in beta any allow to request thumbnails directly from your website, any size you want up to 1000pixels! WOW! thats http://thumbnailspro.com
I instaling now this script, i think it would be great if process will be successful:) interneto svetainiu kurimas
I've read a few of your posts and they're always super insightful -- thank you for always coming up with cool and really sneaky-awesome solutions!
Oy. I've been banging my head against this for the last several hours and haven't found any good clues yet -- When I run my code that utilizes this executable (and I even tried running a copy-paste of yours) locally, webshotcmd.exe runs, but always returns an image of "Action canceled IE wasn unable to link the web page you requested..." even though the test code trying to resolve google.com.
I'm thinking it's a permissions conflict, because the same code run through command line instead of CF works like a charm. But, I've tried changing permissions through IIS and through the actual file privileges -- no beans. Any thoughts?
It probably is some sort of permission thing. I am not sure 100% how CFexecute works, but I guess it uses a ColdFusion "user" on the server. You have to make sure that the security settings for the Internet Zones for that user make sense (I know that often times, IE on the server has VERY tight security).
Are you able to remote into the server and use IE successfully that way?
Wow. Thank you for such a fast response!
I'm running a completely local version of the CF Server, so I don't have to remote to it -- and also I think the user that my IIS uses is a generic 'USERS/[MACHINE-NAME]' when I mess with "http://localhost/..." sites. So, I suppose I can remote to my machine from another machine and see what it lets me do...
Hm. Well, I tried routing my cfexecute through a BAT file, and it gave me the same result. I'll keep trying and I'll post anything that might be of help to posterity :)
Thank you again for ideas on how to *poke* the system.
No problem. I wish I could be more help.
Okay. So I figured it out a while ago, but didn't remember to post till now, when I came across the thread note in my email inbox. It ends up that I had to give 'ColdFusion MX Administrator' higher Log On rights through Microsquish Services. A simple oversight, as it's mentioned in the FAQs on the WebShot site. I suppose though, that it's only 'simple' things that are easy to overlook.
I found interesting free tools and web services do the website screen shot task, I liked to share it here.
i got an error :
Output location [ ... ]
Browser width 
Browser height 
Image quality: 
Navigating web browser [http://www.mySitename.com]
Error: Server not responding, cannot navigate to page
Stopping web browser
File download window blocked
Web browser closed
I'm trying to use webget.exe but whenever i view the file created it is a broken image and when i view the image in the browser it simply has some text with the url of the created image as if it is a text file and not an image. Using the /out path attribute I am specifying the exact name of the image i want it to create so i'm stumped as to why this isnt working.
Can anyone help?