Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('memory_limit', '2048M');
- $images = scandir("C:\\rli");
- function drawArray($arr, $w, $h, $option)
- {
- $leftVote = 0;
- $rightVote = 0;
- $leftCut = $w / 3.5;
- for ($i=0; $i<$h-1; $i++)
- {
- echo "<div>";
- for ($j = 0; $j<$w-1; $j++)
- {
- $r = $arr['c'.$j]['r'.$i]['r'];
- $g = $arr['c'.$j]['r'.$i]['g'];
- $b = $arr['c'.$j]['r'.$i]['b'];
- if ($option[0] == 'grey')
- {
- $avg = round(($r+$b+$g)/3);
- $r = $avg;
- $g = $avg;
- $b = $avg;
- }
- if ($option[0] == 'select')
- {
- if ($option[1] == 'grey')
- {
- $pad = $option[2];
- if ((abs($r - $b) < $pad) && (abs($r - $g) < $pad) && (abs($g - $b) < $pad) && ($r < 150))
- {
- if ($j < $leftCut)
- {
- $leftVote++;
- } else if ($j > $w - $leftCut)
- {
- $rightVote++;
- }
- $r = 255;
- $g = 255;
- $b = 255;
- } else
- {
- $r = 0;
- $g = 0;
- $b = 0;
- }
- } else
- {
- $tArr = $option[1];
- $t_r = $tArr[0];
- $t_g = $tArr[1];
- $t_b = $tArr[2];
- $pad = $option[2];
- $avg = round(($r+$b+$g)/3);
- if ((abs($r - $t_r) < $pad) && (abs($g - $t_g) < $pad) && (abs($b - $t_b) < $pad))
- {
- $r = 255;
- $g = 255;
- $b = 255;
- } else
- {
- $r = 0;
- $g = 0;
- $b = 0;
- }
- }
- }
- echo "<div style=\"display:inline-block;vertical-align:center;width:3px;height:3px;background-color:rgba(".$r.", ".$g.", ".$b.", 1);\"></div>";
- }
- echo "</div>";
- }
- }
- function findArrow($arr, $w, $h, $pad)
- {
- $leftVote = 0;
- $rightVote = 0;
- $leftCut = $w / 3.5;
- for ($i=0; $i<$h-1; $i++)
- {
- for ($j = 0; $j<$w-1; $j++)
- {
- $r = $arr['c'.$j]['r'.$i]['r'];
- $g = $arr['c'.$j]['r'.$i]['g'];
- $b = $arr['c'.$j]['r'.$i]['b'];
- if ((abs($r - $b) < $pad) && (abs($r - $g) < $pad) && (abs($g - $b) < $pad) && ($r < 150))
- {
- if ($j < $leftCut)
- {
- $leftVote++;
- } else if ($j > $w - $leftCut)
- {
- $rightVote++;
- }
- $r = 255;
- $g = 255;
- $b = 255;
- }
- else
- {
- $r = 0;
- $g = 0;
- $b = 0;
- }
- }
- }
- if ($leftVote > $rightVote)
- {
- return ('left');
- } else if ($leftVote < $rightVote)
- {
- return ('right');
- } else
- {
- return ('none');
- }
- }
- $runBot = true;
- $fileNum = 0;
- while($runBot)
- {
- $time_start = microtime(true);
- $imglist = array();
- foreach ($images as $a => $filename)
- {
- array_push($imglist, $filename);
- }
- $imgnum = count($imglist);
- $newFilename = $imglist[$imgnum-1];
- $thisImage = 'c:\\rli\\'.$newFilename;
- $handle = fopen($thisImage, 'rb');
- $thisImage = new Imagick();
- $thisImage->readImageFile($handle);
- $res_W = 300;
- $thisImage->scaleImage($res_W, 0);
- $dim = $thisImage->getImageGeometry();
- $h = $dim['height'];
- $w = $dim['width'];
- $cropStart_X = $res_W * 0.425;
- $thisImage->cropImage(0.15 * $w, 0.8 * $h, $cropStart_X, 0.7 * $h);
- $newW = 0.15 * $w;
- $newH = 0.1 * $h;
- $circle = new ImagickDraw();
- $circle->setFillColor("#FFFFFF");
- $circle->circle($newW/2,($newH/1.1), ($newW/2.6), ($newH/2.6));
- $thisImage->drawImage($circle);
- $rArray = $thisImage->exportImagePixels(0, 0, $w, $h, "RGB", Imagick::PIXEL_FLOAT);
- $pArray = array();
- $colNum = 0;
- $rowNum = 0;
- for ($i=0; $i<count($rArray); $i += 3)
- {
- if (!isset($pArray['c'.$colNum]))
- {
- $pArray['c'.$colNum] = array();
- }
- $pArray['c'.$colNum]['r'.$rowNum] = array('r' => (255 * $rArray[$i]), 'g' => (255 * $rArray[$i+1]), 'b' => (255 * $rArray[$i+2]));
- $colNum++;
- if ($colNum > $w-1)
- {
- $rowNum++;
- $colNum = 0;
- } else
- {
- }
- }
- drawArray($pArray, $newW, $newH, [null]);
- drawArray($pArray, $newW, $newH, ['select', [150, 150, 150], 20]);
- drawArray($pArray, $newW, $newH, ['select', 'grey', 20]);
- $date = new dateTime();
- $ts = $date->getTimeStamp();
- $newDir = findArrow($pArray, $newW, $newH, 10);
- echo $newDir."<br>";
- $filename = 'C:\\kb\\keybot.txt';
- $update = fopen($filename, "w");
- fwrite($update, $newDir);
- fclose($update);
- $time_end = microtime(true);
- $time_script = $time_end - $time_start;
- // echo "script time was ".$time_script;
- $runBot = false;
- }
- echo "<script>setTimeout(function(){location.reload();}, 500);</script>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment