This is a little script I wrote to take automatic screenshots of some of our sites. We keep a table (customers) with all of our customers and thier domains. This reads through that table, and passes each url to HTMLDOC (www.easysw.com/htmldoc). HTMLDOC stores a PDF version of a webpage. Then it uses GhostScript to convert the pdf file to a jpg.
The last part is what you are interested in.
passthru("gs -sDEVICE=jpeg -sOutputFile=./shots/$a_row[name]1.jpg -r300x300 ./pdf/$a_row[name].pdf");
Here is the whole script.
$link = mysql_connect ($server, $user, $password);
if (! $link)
{
die ("Couldn't connect to mySQL server");
}
if (!mysql_select_db ($db, $link) )
{
die ("Coldn't open $db: ".mysql_error() );
}
$getcust = mysql_query("SELECT * FROM customers");
while($a_row = mysql_fetch_array($getcust))
{
echo "$a_row[name]\r\n";
$a_row[name] = str_replace(" ", "_", $a_row[name]);
passthru("htmldoc --webpage -f /vhosts/webpieces.net/httpdocs/screenshots/pdf/$a_row[name].pdf [url]http://[/url]$a_row[location]");
passthru("gs -sDEVICE=jpeg -sOutputFile=./shots/$a_row[name]1.jpg -r300x300 ./pdf/$a_row[name].pdf");
$image = "./shots/$a_row[name]1.jpg";
$thumbImgResized = Imagecreatetruecolor(640, 480);
imagecopyresampled($thumbImgResized, ImageCreateFromJPEG($image), 0 , 0 , 0, 0, (640), (800), 2479, 3300);
ImageJPEG($thumbImgResized, "./shots/$a_row[name].jpg");
ImageDestroy($thumbImgResized);
passthru("rm -rf $image");
}
Hope this helps!