Solved

Scroll before taking a screenshot in PHP.

Posted on 2011-09-28
2
349 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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 count occurrences of each item in an array.

930 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

14 Experts available now in Live!

Get 1:1 Help Now