Hi all, I'm working on a web site that I need to show users a preview of their design choices before checkout but of course, using HTML they've be able to simply download the solution before paying. To which I though it would be better to use an HTML2JPG converter but I've been struggling to find a good one.
So my question is ... does anybody have a good HTML2JPG converter that will work in PHP? I know there's a couple for Windows ISS but in this particular case, I need to stay on Linux.
thanks, Chris
Christopher Ross
Web Evangelist
http://www.thisismyurl.com


decibel.places posted this at 18:20 — 7th January 2009.
He has: 1,550 posts
Joined: Jun 2008
Hi Chris,
Welcome to TWF!
The projects/portfolio section on this site uses http://www.websnapr.com/
might work for you...
pr0gr4mm3r posted this at 19:21 — 7th January 2009.
He has: 1,394 posts
Joined: Sep 2006
I think the OP needs something more in house than websnapr. There is a script here that can make a PDF for you. If you need it in an image format, there should be a script that could take it from PDF to the image format you're looking for.
PHP Starter
thisismyurl posted this at 20:00 — 7th January 2009.
They have: 3 posts
Joined: Jan 2009
Thanks guys, both suggestions are great. I'll take a look at WebSnapr but based on the requirement to do multiple views of variable data, I might need to go with the PDF version. I'll let you both know how it turns out.
Christopher Ross
Web Evangelist
http://www.thisismyurl.com
kazimmerman posted this at 20:18 — 7th January 2009.
He has: 670 posts
Joined: Jul 2005
I've never tried it, but I think you could utilize the imagegrabscreen() or imagegrabwindow() functions from the GD library to output an image of the current screen. They should both work something like this:
<?php//All of your normal code would go here
//But before exiting, grab a snapshot
$image = imagegrabscreen();
imagejpeg($image,"my_screenshot.jpeg");
imagedestroy($image);
?>
The imagegrabwindow() function requires more parameters that I haven't investigated, but the imagegrabscreen() function I believe would capture the entire screen, not just the window of focus.
-Kurtis
JeevesBond posted this at 17:46 — 8th January 2009.
He has: 3,876 posts
Joined: Jun 2002
I think you're right to go with a third-party solution. Generating a screen shot from the server can be a real hassle: Web servers don't generally come with a window manager installed, as they take up valuable RAM. Xorg is taking up 200MB on my desktop machine, for example (although you'll need much less for just taking a screen shot of a Web page).
I investigated doing screen shots for our project pages, but found that installing Xorg, worrying about the amount of RAM it would take, and setting it all up was far more work than just using a third-party solution.
Good luck with your search though, and welcome to the forums!
a Padded Cell our articles site!
pr0gr4mm3r posted this at 17:51 — 8th January 2009.
He has: 1,394 posts
Joined: Sep 2006
Those third party services are designed for public pages though, not HTML code that the OP is trying to keep private.
PHP Starter
JeevesBond posted this at 17:58 — 8th January 2009.
He has: 3,876 posts
Joined: Jun 2002
I meant to include your html2fpdf in the phrase third-party solution. Just haven't had any caffeine yet today.
I really should remedy that problem immediately!
a Padded Cell our articles site!
thisismyurl posted this at 22:28 — 9th January 2009.
They have: 3 posts
Joined: Jan 2009
Hey all, the html2fpdf did most of what I needed so thanks for the great help.
AndrewCF posted this at 14:01 — 24th January 2009.
They have: 3 posts
Joined: Jan 2009
Hi Chris,
If you website based Windows server, you can use this HTML Convert SDK - ACA WebThumb ActiveX.
A simple PHP Script for converting HTML to image:
<?php
$t_xMaker = new COM('ACAWebThumb.ThumbMaker')
or die("Start ACAWebThumb.ThumbMakerfailed");
$t_xMaker->SetURL("http://www.webmaster-forums.net");
if ( 0 == $t_xMaker->StartSnap() )
{
// Snap successful, call SetImageFile() to save the image.
echo "Take screenshot successful." ;
$t_xMaker->SaveImage("c:/webmaster-forums.png");
}
?>
If you PHP version >= 5.2.2, you can using following code:
<?php
$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate("http://www.webmaster-forums.net");
/* Still working? */
while ($browser->Busy) {
com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
$browser->Quit();
imagepng($im, "webmaster-forums.png");
imagedestroy($im);
?>