Solved

Scroll before taking a screenshot in PHP.

Posted on 2011-09-28
2
342 Views
Last Modified: 2012-05-12
Hello,

I have the following piece of code. Is it possible that before php takes the screenshot of the window, to scroll down 200 pixels? The area I need to take a screenshot from is not visible 100% without scrolling.

Thanks!



$Browser = new COM('InternetExplorer.Application');
$Browserhandle = $Browser->HWND;
$Browser->Visible = true;
$Browser->Fullscreen = true;
$Browser->Navigate('http://www.mysite.com');
while ($Browser->Busy) {
com_message_pump(8000);
}
$img = imagegrabwindow($Browserhandle, 0);
$Browser->Quit();
imagejpeg($img, 'screenshot.jpg', 100);

Open in new window

0
Comment
Question by:infodigger
2 Comments
 
LVL 6

Accepted Solution

by:
neorush earned 500 total points
ID: 36719108
You would need to use WScript.Shell, I have no way of testing this, but it is pretty close...

$shell = new COM("WScript.Shell");
$Browser = new COM('InternetExplorer.Application');
$Browserhandle = $Browser->HWND;
$Browser->Visible = true;
$Browser->Fullscreen = true;
$Browser->Navigate('http://www.mysite.com');
while ($Browser->Busy) {
com_message_pump(8000);
}
// Scroll down, could also try a few {DOWN}{DOWN}{DOWN}{DOWN} "down arrows"
$shell->SendKeys("{PGDN}"); // see http://www.developerfusion.com/article/57/sendkeys-command/
$img = imagegrabwindow($Browserhandle, 0);
$Browser->Quit();
imagejpeg($img, 'screenshot.jpg', 100);

Open in new window

0
 

Author Comment

by:infodigger
ID: 36813617
Hi Neorush,

Is it also possible to make php focus on that Window as well? Because I was able to send the keys but they are sent to the window which is currently open not to the new one.

Thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now