Page 1 of 2

webpage as image

Posted: Wed Jun 07, 2006 11:12 am
by gurjit
hi,

is there anyway i can display a website as a thumbnail by pointing to it.

so for example

http://www.google.com

will show me a small thumbnail of there homepage as a gif or jpeg

Posted: Wed Jun 07, 2006 11:15 am
by MrPotatoes
i've never done or thought about that but i think you would have to cache it first?.

in C++ this would be easy. i would take a screen dump of the web page and thumbnail it for later. but this is a great idea and i woul like to know how to do it

Posted: Wed Jun 07, 2006 11:17 am
by GM
The answer is 'Yes' - it is possible, I've seen it done.

Unfortunately, I don't have the faintest idea how...

Sorry. :(

Posted: Wed Jun 07, 2006 11:19 am
by PrObLeM
I'm afraid it isn't possible in php. Unless you exec a program on the server that would do it. ( http://www.php.net/exec )

Posted: Wed Jun 07, 2006 11:27 am
by PrObLeM

Posted: Wed Jun 07, 2006 11:32 am
by ok
There is a firefox ext which does this: Cooliris Preview.
Download the ext and then unzip it and look at the JS source!

Posted: Wed Jun 07, 2006 11:37 am
by gurjit
how can i embed a command line screen shot in php script

Posted: Wed Jun 07, 2006 11:42 am
by PrObLeM
well it would take a screenshot, then save it on the server. then you would access the file like anyother image

Posted: Wed Jun 07, 2006 11:45 am
by gurjit
only problem is that I will be doing a search over 70,000 records and have to create images for each result set.

Posted: Wed Jun 07, 2006 11:49 am
by gurjit
anyone familiar with this:

http://www.imagemagick.org/script/index.php

will this do the trick

Posted: Wed Jun 07, 2006 1:32 pm
by ok
Try this:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Preview </TITLE>
<SCRIPT language="JavaScript" type="text/javascript">
function ShowPreview(id)
{
	var divElement = document.all.item(id);
	divElement.style.display = "block";
}

function HidePreview(id)
{
	var divElement = document.all.item(id);
	divElement.style.display = "none";
}
</SCRIPT>
</HEAD>

<BODY>
<a href="http://www.google.com" onmouseover="ShowPreview('wwwdotgoogledotcom');" onmouseout="HidePreview('wwwdotgoogledotcom');">www.google.com</a>
<div id="wwwdotgoogledotcom" style="display: none; font-size: 80%;">
<iframe src="http://www.google.com" width="200" height="200" scrolling="no"></iframe>
</div>
</BODY>
</HTML>

Posted: Wed Jun 07, 2006 2:32 pm
by ambivalent
That's a neat trick, noted for future use. :wink:

Posted: Wed Jun 07, 2006 2:42 pm
by ok
Does somebody know how to convert PDF to image???

Posted: Wed Jun 07, 2006 3:53 pm
by ok
After a long long long long long .... research i found the necessary softwares for converting HTML to Image!!!!!!!

1. Download and copy to the server root: http://www.tufat.com/script19.htm.
2. Download and install: http://www.imagemagick.org/www/binary-r ... ml#windows (there is also unix release).
3. Check that you can use exec().
4. Use this code to convert HTML to Image:

Code: Select all

<?php
$docroot = "C:\\Program_Files\\Apache Group\\Apache2\\htdocs\\";
$html2ps_dir = "html2ps";
$site = "http://www.google.com";
$handle = fopen("http://localhost/".$html2ps_dir."/html2ps.php?process_mode=single&URL=".$site."&pixels=640&scalepoints=1&renderimages=1
&renderlinks=1&renderfields=1&media=Letter&cssmedia=screen&leftmargin=30&rightmargin=15&topmargin=15&bottommargin=15
&encoding=&method=fpdf&pdfversion=1.3&output=2", "r");
while(!feof($handle))
{
	$content .= fread($handle, 4096);
}
fclose($handle);
$pos = strrpos($content, "/");
if($pos === FALSE)
{
	die("Problem");
}else{
	$filename = substr($content, $pos+1, strlen($content)-1);
}
echo $filename;
exec('C:\Program_Files\ImageMagick-6.2.8-Q16\convert.exe "".$docroot.$html2ps_dir."\out\\'.$filename.'" "".$docroot."sample.jpeg"');
?>
Run this script and Enjoy! :D

P.S
Additional links:

Posted: Thu Jun 08, 2006 3:46 am
by gurjit
I ran this script and got errors. heres my script after installing and verifying imagemagick works properly

Code: Select all

<?php 
$docroot = "C:\\myfolder\\"; 
$html2ps_dir = "html2ps_v194"; 
$site = "http://www.google.com"; 
$handle = fopen("http://localhost/".$html2ps_dir."/html2ps.php?process_mode=single&URL=".$site."&pixels=640&scalepoints=1&renderimages=1 
&renderlinks=1&renderfields=1&media=Letter&cssmedia=screen&leftmargin=30&rightmargin=15&topmargin=15&bottommargin=15 
&encoding=&method=fpdf&pdfversion=1.3&output=2", "r"); 
while(!feof($handle)) 
{ 
        $content .= fread($handle, 4096); 
} 
fclose($handle); 
$pos = strrpos($content, "/"); 
if($pos === FALSE) 
{ 
        die("Problem"); 
}else{ 
        $filename = substr($content, $pos+1, strlen($content)-1); 
} 
echo $filename; 
exec('C:\Program_Files\ImageMagick-6.2.8-Q16\convert.exe "".$docroot.$html2ps_dir."\out\\'.$filename.'" "".$docroot."sample.jpeg"'); 
?>
The error i get is

Code: Select all

Warning: fopen(http://localhost/html2ps_v194/html2ps.php?process_mode=single&URL=http://www.google.com&pixels=640&scalepoints=1&renderimages=1 &renderlinks=1&renderfields=1&media=Letter&cssmedia=screen&leftmargin=30&rightmargin=15&topmargin=15&bottommargin=15 &encoding=&method=fpdf&pdfversion=1.3&output=2) [function.fopen]: failed to create stream: HTTP request failed! HTTP/1.1 400 Bad Request in c:\inetpub\wwwroot\imagemagic.php on line 15

Warning: feof(): supplied argument is not a valid stream resource in c:\inetpub\wwwroot\imagemagic.php on line 16

Warning: fread(): supplied argument is not a valid stream resource in c:\inetpub\wwwroot\imagemagic.php on line 18

Notice: Undefined variable: content in c:\inetpub\wwwroot\imagemagic.php on line 18

Warning: feof(): supplied argument is not a valid stream resource in c:\inetpub\wwwroot\imagemagic.php on line 16

Warning: fread(): supplied argument is not a valid stream resource in c:\inetpub\wwwroot\imagemagic.php on line 18

Warning: feof(): supplied argument is not a valid stream resource in c:\inetpub\wwwroot\imagemagic.php on line 16

Warning: fread(): supplied argument is not a valid stream resource in c:\inetpub\wwwroot\imagemagic.php on line 18

Warning: feof(): supplied argument is not a valid stream resource in c:\inetpub\wwwroot\imagemagic.php on line 16

Warning: fread(): supplied argument is not a valid stream resource in c:\inetpub\wwwroot\imagemagic.php on line 18

Warning: feof(): supplied argument is not a valid stream resource in c:\inetpub\wwwroot\imagemagic.php on line 16

Warning: fread(): supplied argument is not a valid stream resource in c:\inetpub\wwwroot\imagemagic.php on line 18