Page 1 of 2
Screenshot via PHP?
Posted: Thu Jan 06, 2005 3:41 pm
by Todd_Z
This is a rather odd request, but I was wondering if I could go to a script on a webpage and it would run a program on my computer then show the file with a content-type of a jpg. Is this at all possible to even run a program on my computer?
Posted: Thu Jan 06, 2005 3:44 pm
by feyd
[php_man]system()[/php_man]/[php_man]exec()[/php_man]
Posted: Thu Jan 06, 2005 4:37 pm
by Todd_Z
Code: Select all
<?php
$neoShooter = "neoshooter.exe /shootnow";
chdir("*FILEPATH*/neoshooter403/");
exec($neoShooter);
?>
I can get neoshooter ( the program that takes a screenshot and then saves it to a folder) to work in the command prompt, but when I run this, php just doesn't stop loading and nothing happens. Any errors with my code?
Posted: Thu Jan 06, 2005 4:48 pm
by feyd
neoshooter may hang php, I'm not sure.
Posted: Thu Jan 06, 2005 5:07 pm
by markl999
Just as a note i use PHP with exec to capture screenshots automatically but i use
grab to do it.
Posted: Thu Jan 06, 2005 5:21 pm
by Todd_Z
do you mind posting code or protocal for your script?
Posted: Thu Jan 06, 2005 5:35 pm
by markl999
Well it very customised as it auto reads url's from a database, grabs the shot, sizes it to a large and small shot then ftp's it to a remote site and it also uses
winbinder for it's gui interface and
php_dhtml for the actual IE side of it (it's easier on *nix but i have no choice but to use windows for this :0). If you're not grabbing website screenshots, only a desktop screenshot then it's easier as you don't need the IE/COM part of the below.
But, having said that the actual grabbing of a screenshot it relatively simple.
First you need to grab the screenshot: i use php_dhtml for this but a simple
COM call to load an IE window with a url will do. Then i do an exec call along the lins of 'grab -f foo.bmp -t bar' where bar is the title of the IE window. If you're just grabbing a desktop shot then see the grab url above for the arguments to grab the whole desktop.
Then i use
ImageMagicks convert utility to do the resizing...again see the docs for convert for the relevant command line arguments.
I might have made this seem a bit complex but it's really just a case of grabbing then converting both of which use exec() to shell out a command to grab and convert respectively. Hope this help a little

Posted: Thu Jan 06, 2005 7:13 pm
by Todd_Z
When I go to run->cmd->grab -f picture.bmp -p -t Program manager I get a picture, but when i execute
Code: Select all
<?
exec("grab -f picture.bmp -p -t Program manager");
?>
I get nothing... any ideas?
But when I do
I get the full help
I'm running an apache server... is it possible that thats the reason i can't get to the regular command prompt for my computer?
Posted: Thu Jan 06, 2005 7:17 pm
by markl999
It maybe the space in Program Manager so first try:
exec('grab -f picture.bmp -p -t "Program manager"');
Also it may just be a path problem. Make sure grab.exe is in your php/apache's path, i.e c:\WINDOWS\system32\grab.exe
Posted: Thu Jan 06, 2005 7:49 pm
by Todd_Z
I have it in the folder where the script is... plus since i do grab - h and get a response, that means it recognizes it... but it wont reply to any other commands - including the one posted above.
Posted: Thu Jan 06, 2005 7:50 pm
by feyd
maybe runs out of memory?
Posted: Thu Jan 06, 2005 7:52 pm
by Todd_Z
I made a simple batch, when I run the batch, it runs the grab command, then responds Done. ~ I run this batch through exec() in php, get a returned value of Done, but no picture appears...
Posted: Thu Jan 06, 2005 7:53 pm
by feyd
no picture appears where? in the folder, or in the browser?
Posted: Thu Jan 06, 2005 7:55 pm
by markl999
Try a 'grab -l'
It will show the window titles that are available to capture, check that 'Program Manager' is in the list.
Posted: Thu Jan 06, 2005 8:00 pm
by Todd_Z
grab -l returns nothing, in the php error_log:
[Thu Jan 06 20:59:57 2005] [error] [client 127.0.0.1] No matching window found for "test"\r But when i run the same command in the command prompt, it works...