1,105,331 Community Members

screenshot of any webpage using php

Member Avatar
sanjaypandit
Newbie Poster
23 posts since May 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I want to save screenshot of any webpage using php. i search in google but i dont found any result for linux server. i got some window server result using imagegrabwindow() function. is their anotherway for linux server. i install one script with Class COM i which internet exp. open and take a screenshot. but how it will work in linux server

thanks

Member Avatar
cwarn23
Occupation: Genius
3,028 posts since Sep 2007
Reputation Points: 387 [?]
Q&As Helped to Solve: 281 [?]
Skill Endorsements: 15 [?]
Team Colleague
Featured
 
0
 

I'm not sure about directly creating this script from scratch but perhaps there might be an api that you can use. So try and google for a webpage screen capture api.

Member Avatar
hemgoyal_1990
Junior Poster
176 posts since Aug 2007
Reputation Points: 5 [?]
Q&As Helped to Solve: 17 [?]
Skill Endorsements: 0 [?]
 
1
 

use the below script:

<?PHP

$image = "http://images.websnapr.com/?size=s&url=$url";

echo "<img src=\"$image\" width=\"202\" height=\"152\" alt=\"Screen Shot.\">";

?>

The above will capture 202*152 size image.

Member Avatar
vaultdweller123
Posting Pro
577 posts since Sep 2009
Reputation Points: 32 [?]
Q&As Helped to Solve: 84 [?]
Skill Endorsements: 2 [?]
 
0
 

hit print screen! :twisted:

Member Avatar
diafol
Where are my eyes?
12,977 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

hit print screen! :twisted:

Chortle! Nice one.

Thumbshots.org have a service. The imagegrab..() functions work with Windows (and only IE - *I think*). I could never get it to work. I always thought that getting a screenshot from an url was a big 'no-no', as it usually got info from the client's browser - this would pose a pretty horrible security risk.

This could mean that a site could get my active window or desktop screenshot. Gawd, how would I explain that in my necrophiliacs anonymous sessions?

Member Avatar
amitgmail
Newbie Poster
4 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hi

<?PHP
     
    $image = "http://images.websnapr.com/?size=s&url=$url";
     
    echo "<img src=\"$image\" width=\"202\" height=\"152\" alt=\"Screen Shot.\">";
     
    ?>

this is not working now any idea about new code..??????????

Member Avatar
cwarn23
Occupation: Genius
3,028 posts since Sep 2007
Reputation Points: 387 [?]
Q&As Helped to Solve: 281 [?]
Skill Endorsements: 15 [?]
Team Colleague
Featured
 
0
 

hi <?PHP

$image = "http://images.websnapr.com/?size=s&url=$url";

echo "<img src=\"$image\" width=\"202\" height=\"152\" alt=\"Screen Shot.\">";

?>

this is not working now any idea about new code..??????????

hi, please use lower case <?php and that should solve your problem. :)

Member Avatar
amitgmail
Newbie Poster
4 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-2
 

what a foolish Answer.......Plz sumbit any supportive answer

Member Avatar
cereal
Posting Virtuoso
1,710 posts since Aug 2007
Reputation Points: 461 [?]
Q&As Helped to Solve: 345 [?]
Skill Endorsements: 44 [?]
 
0
 

Check the code of timthumb script:

http://timthumb.googlecode.com/svn/trunk/timthumb.php

I never tried that but it gives the ability to create screenshots of websites, you will need access to the command line of your webserver, in shared hostings this may not be possible. Bye.

Member Avatar
veedeoo
Veteran Poster
1,016 posts since Oct 2011
Reputation Points: 314 [?]
Q&As Helped to Solve: 166 [?]
Skill Endorsements: 17 [?]
 
0
 

Hi,

Try this,

<?php
## define your url
## change comments tags to the proper syntax as recommended by php.net.
## unless you are a developer, you can give reason why these ## are valid.
## even if the rest of the world would argue that it is wrong, 
## it does not mean it is not valid. 

$url = "http://www.daniweb.com/web-development/php/threads/256243";
echo '<img src="http://open.thumbshots.org/image.aspx?url='.$url.'" width = "150" height = "150" />';
	
?>
Member Avatar
cwarn23
Occupation: Genius
3,028 posts since Sep 2007
Reputation Points: 387 [?]
Q&As Helped to Solve: 281 [?]
Skill Endorsements: 15 [?]
Team Colleague
Featured
 
1
 

Hi,

Try this,

<?php
## define your url
## change comments tags to the proper syntax as recommended by php.net.
## unless you are a developer, you can give reason why these ## are valid.
## even if the rest of the world would argue that it is wrong, 
## it does not mean it is not valid. 

$url = "http://www.daniweb.com/web-development/php/threads/256243";
echo '<img src="http://open.thumbshots.org/image.aspx?url='.$url.'" width = "150" height = "150" />';
	
?>

That's exactly what I proposed and took this many posts to work that out.

Member Avatar
amitgmail
Newbie Poster
4 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

ya thanks for sharing this ,this is very good as i found this one... now is we want to save this screenshot in server side php. any idea how to do this......

Member Avatar
veedeoo
Veteran Poster
1,016 posts since Oct 2011
Reputation Points: 314 [?]
Q&As Helped to Solve: 166 [?]
Skill Endorsements: 17 [?]
 
1
 

@ amitgmail,

Yes, you can save the thumbs if you want. There are two options in doing this.

1. You can use imagecreatefromjpeg. This method requires the allow_url_fopen must be ON in your php.ini file. The consequences of using this method is somewhat greater exposure to security holes if not use properly. I will not discuss the security vulnerability here about the url_fopen, because it will fill up this page. You can search url_fopen. This topic has been discussed in great detail in php security consortium. Anyone with proper knowledge of how to take advantage of this vulnerability can easily transfer malicious file on your server. Meaning, once it is transferred they can execute their codes.

Here is how you will save the screenshots using the first option above..Let's use my example codes provided on the previous page of this thread.

<?php
## define your url

$url = "http://www.daniweb.com/web-development/php/threads/256243";

## let's change the codes
## define the image url just for the purpose of displaying it on the page.
$img_url = '<img src="http://open.thumbshots.org/image.aspx?url='.$url.'" width = "150" height = "150" />';

## define the location of the image we are going to save.
$img_url1 = 'http://open.thumbshots.org/image.aspx?url='.$url;
## let's show the screenshot
echo $img_url;

## define the destination directory of the saved screenshot
## by the way I would like itemized everything here instead of writing them in condense form
## so that people who needs it,  will easily understand these things.
## define the file name of the screenshot image and the directory.
$img_dir ="test/whatever.jpg";


## let's use the not-so-safe option one
$save_img = @imagecreatefromjpeg($img_url1);

## let's save the above image
## the syntax below is just nothing but @imagejpeg("WHAT to save ","WHERE to save it")
@imagejpeg($save_img, $img_dir);	
?>

2. Now the second option which is a lot safer than the above implementation. This time we will be using cURL. cURL is a very powerful tool of PHP. Allow me to revise the above codes to implement cURL.

<?php
## define your url

$url = "http://www.daniweb.com/web-development/php/threads/256243";

## let's change the codes
## define the image url just for the purpose of displaying it on the page.
$img_url = '<img src="http://open.thumbshots.org/image.aspx?url='.$url.'" width = "150" height = "150" />';

## define the location of the image we are going to save.
$img_url1 = 'http://open.thumbshots.org/image.aspx?url='.$url;
## let's show the screenshot
echo $img_url;

## define the destination directory of the saved screenshot
## by the way I would like itemized everything here instead of writing them in condense form
## so that people who needs it,  will easily understand these things.
## define the file name of the screenshot image and the directory.
$img_dir ="test/whatever.jpg";

## once again it is your job to search and learn many different 
## options in using cURL, most importantly if the target server's url is requiring a referrer.
## you can easily add referrer option on your cURL's instance if needed be. Even adding a browser agent type
## can be achieved.
$ch = curl_init ($img_url1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$img_data=curl_exec ($ch);
curl_close ($ch);

$fp = fopen($img_dir,'w');

fwrite($fp, $img_data);
fclose($fp);
		
?>

That's it for the code writing for this week..will come again by next week to write something up.. :)

Member Avatar
amitgmail
Newbie Poster
4 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

@Veedeoo ,

Thanks for your Valuable suggestion an co-operattion....

Member Avatar
Maximus1983
Newbie Poster
2 posts since May 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

GrabzIt is a great free service for this. It currently has a PHP API as well as a .NET one.

They have a free PHP library you can download that includes a working sample so you can get going really quickly.

The basic idea is that you use the GrabzIt client to calls the screenshot service passing the URL you want a screenshot of and the callback URL. The callback url will then save the result for you.

include("GrabzItClient.class.php");

//Create the GrabzItClient class
//Replace "APPLICATION KEY", "APPLICATION SECRET" with the values from your account!
$grabzIt = new GrabzItClient("APPLICATION KEY", "APPLICATION SECRET");
//Take the picture the method will return the unique identifier assigned to this task
$id = $grabzIt->TakePicture("http://www.google.com", "http://www.example.com/GrabzItHandler.php");

Here is their example callback class:

include("GrabzItClient.class.php");

$message = $_GET["message"];
$customId = $_GET["customid"];
$id = $_GET["id"];
$filename = $_GET["filename"];

//Custom id can be used to store user ids or whatever is needed for the later processing of the
//resulting screenshot

$grabzIt = new GrabzItClient("APPLICATION KEY", "APPLICATION SECRET");
$result = $grabzIt->GetPicture($id);

if (!$result)
{
    return;
}

//Ensure that the application has the correct rights for this directory.
file_put_contents("images" . DIRECTORY_SEPARATOR . $filename, $result);
Member Avatar
rasfoiesc
Newbie Poster
1 post since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I want to creat some thumbs / images of the firs page of each .doc and displayed it to the left of the title.

See for example:

http://www.rasfoiesc.com/educatie/literatura/index4.php here is a list of doc. On the left i want to be the thumb too.

  • so i want to generate images thumbs for eache Word / doc .

How can i do that?

MikeWay
Newbie Poster
1 post since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

I use these guys, seem to work well and provide loads of PHP API stuff. Also the cheapest i found..
MPZImg.com

Examples like:

<img src="http://serv.mpzimg.com/?uid=APIKEY&mw=200&mh=350&theURL=http://news.bbc.co.uk">

Simples :)

fsadfsadfsad
Newbie Poster
1 post since Jun 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

the easiest way I know is to use http://www.thumbs4free.net/

to get the google page screenshot use

http://api.thumbs4free.net/Thumbs/View?url=http://www.google.com 
Member Avatar
user1439u
Newbie Poster
1 post since Aug 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
Member Avatar
jsobrier
Newbie Poster
2 posts since Jan 2014
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Infraction Points: 5
 
0
 

If you go the route of using a web service, you can check the PHP library of Browshot.

You
Post:
Start New Discussion
View similar articles that have also been tagged: