Screenshot via PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Screenshot via PHP?

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[php_man]system()[/php_man]/[php_man]exec()[/php_man]
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

neoshooter may hang php, I'm not sure.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Just as a note i use PHP with exec to capture screenshots automatically but i use grab to do it.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

do you mind posting code or protocal for your script?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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 ;)
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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

Code: Select all

<?
shell_exec("grab -h");
?>
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?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

maybe runs out of memory?
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post 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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

no picture appears where? in the folder, or in the browser?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

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