I am trying to prepare desktop application using PHP Nightrain. I want to take screen shot of open window after every 10 seconds. I tried using html2canvas but it is taking screen shot of application open page. If I will open Microsoft word and work inside it that time i want screen shot of it using PHP. Is it possible using PHP? And one more thing I want to make desktop application using PHP which is OS compatible.
-
1No, it is not possible unless the PHP code is running on the client's machine (not likely, as PHP usually runs server-side). What you are attempting is a serious privacy issue, which is probably why no such API exists. The only way you could do this would be via browser extensions and/or NSAPI/PPAPI/ActiveX applets. – Alexander O'Mara Jul 20 '15 at 05:26
-
Using PHP Nightrain application will run like desktop application and it is not running inside browser. If I run exe file of PHP Nightrain then it opens one window. – Kinjal Modi Jul 20 '15 at 05:51
-
In that case, if Nightrain does not have such an API, you could probably call external executables using `shell_exec`, etc. OS X has a built-in command for this. IDK about other operating systems. – Alexander O'Mara Jul 20 '15 at 05:55
2 Answers
This cannot be done with php alone. You will need javascript to take the screenshot, convert it into a string and send it via ajax to a php script which would then save the content.
To do that you can use this library http://html2canvas.hertzen.com/. Now the magic happens in the next few lines of code:
// an example html page
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script type="text/javascript" src="./javascripts/html2canvas.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#screenshot').on('click', function(e){
e.preventDefault();
html2canvas($('body'), {
onrendered: function(canvas){
var imgString = canvas.toDataURL();
window.open(imgString);
$.ajax({
url: '',
type: 'POST',
data: {
file: imgString
},
success: function(response){
//alert('Everything works fine.');
},
error: function(response){
//alert('Server response error.');
}
});
}
});
});
});
</script>
</head>
<body>
As far as the IE 7 & 8 support goes - google (and other giant web sites) have stated to support up to 1 version back from the latest. So, if the current version is 10, they will only support 9 and 10. I believe this is a good practice and I'm using it with my clients as well. IE < 8 is a big pain in the ... to be working with if you're developing advanced web pages. If your client still insists having IE 7 & 8 support, you may want to checkout Modernizr and html5shiv which may be able to help you bring the html5 support to IE.

- 4,740
- 3
- 26
- 46
-
"I tried using html2canvas but it is taking screen shot of application open page. If I will open Microsoft word and work inside it that time i want screen shot of it using PHP." – Alexander O'Mara Jul 20 '15 at 05:42
-
I have tried it using html2canvas but it is taking the running page of application. I want PHP application will run after every 10 seconds and take screen shot of whenever i work in the system. – Kinjal Modi Jul 20 '15 at 05:43
Will only work on servers, check how about this:
<?php
// capture the screen
$img = imagegrabscreen();
imagepng($img, 'screenshot.png');
?>
OR
<?php
// Capture the browser window
$Browser = new COM('InternetExplorer.Application');
$Browserhandle = $Browser->HWND;
$Browser->Visible = true;
$Browser->Fullscreen = true;
$Browser->Navigate('http://www.stackoverflow.com');
while($Browser->Busy){
com_message_pump(4000);
}
$img = imagegrabwindow($Browserhandle, 0);
$Browser->Quit();
imagepng($img, 'screenshot.png');
?>
Searching is useful for a fast answer ;)

- 1
- 1

- 4,740
- 3
- 26
- 46
-
It captures browser window but I want to capture system open window. This works for windows only. – Kinjal Modi Jul 20 '15 at 06:01