2010/12/07

The image search on page function.

At the Human Emulator program version 4.0.10 were added two functions: “get_x_in_webpage_picture” and “get_u_in_webpage_picture” to the "$webpage" object. Their emergence has passed quietly, but it also deserves separate description cause of opportunity it gives.


The ability to find coordinates of something by the image pattern – is the aim of these functions. The image on the picture is compared automatically with site screenshot. The coordinates computed and returned when they coincide. If desired element "floats" with each page refreshing or you're working with Flash, in which is difficult to make a script, using only the cliques in the coordinates, - then these functions will help.


For example, let's get on page http://tinymce.moxiecode.com/examples/full.php and make the image sample. The image size is not particularly important, the function will return the coordinates of the first full match. The comparison is the result of color and position of each pixel. You have to save image in bmp extension and 24 bpp. There is a copy of picture I took for the experiments:


XHE

Now there is the script turn. You can get the coordinates, using the following code:


require("../Templates/xweb_human_emulator.php");

$x=$webpage->get_x_in_webpage_picture("C:\\1.bmp");
$y=$webpage->get_y_in_webpage_picture("C:\\1.bmp");
echo " The coordinates of the image:$x $y";

As you guessed, I named the picture «1.bmp» and saved it in drive C: root. Now, after running this script, we will have its coordinates. You can easily click on them by function “$mouse-> click ($x, $y);” when you have its coordinates. Add it to your script, check the result and experiment with other samples.


Thus, you can adapt the mouse work with the help of these functions, regardless of the browser window size and key elements location.


Convenient functional for saving pictures samples will be added in upcoming versions. Feel free to say any of your thoughts about the expansion of these functions in ICQ Support.

No comments:

Post a Comment