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

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 for diafol

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?

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 <?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. :)

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

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.

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" />';
	
?>

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.

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......

@ 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.. :)

@Veedeoo ,

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

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);

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?

Its the hover effect, like if i mouse over www.softexsol.com then its view will be shown, I wana to show its image in img src tag.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.