Guest User

Untitled

a guest
Sep 22nd, 2018
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.32 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. ini_set('memory_limit', '2048M');
  5. $images = scandir("C:\\rli");
  6.  
  7. function drawArray($arr, $w, $h, $option)
  8. {
  9.     $leftVote = 0;
  10.     $rightVote = 0;
  11.     $leftCut = $w / 3.5;
  12.     for ($i=0; $i<$h-1; $i++)
  13.     {
  14.         echo "<div>";
  15.         for ($j = 0; $j<$w-1; $j++)
  16.         {
  17.         $r = $arr['c'.$j]['r'.$i]['r'];
  18.         $g = $arr['c'.$j]['r'.$i]['g'];
  19.         $b = $arr['c'.$j]['r'.$i]['b'];
  20.  
  21.         if ($option[0] == 'grey')
  22.             {
  23.             $avg = round(($r+$b+$g)/3);
  24.             $r = $avg;
  25.             $g = $avg;
  26.             $b = $avg;
  27.             }
  28.         if ($option[0] == 'select')
  29.             {
  30.             if ($option[1] == 'grey')
  31.                 {
  32.                 $pad = $option[2];
  33.                 if ((abs($r - $b) < $pad) && (abs($r - $g) < $pad) && (abs($g - $b) < $pad) && ($r < 150))
  34.                     {
  35.                     if ($j < $leftCut)
  36.                         {
  37.                         $leftVote++;
  38.                         } else if ($j > $w - $leftCut)
  39.                         {
  40.                         $rightVote++;
  41.                         }
  42.                 $r = 255;
  43.                 $g = 255;
  44.                 $b = 255;
  45.                 } else
  46.                 {
  47.                 $r = 0;
  48.                 $g = 0;
  49.                 $b = 0;
  50.                 }
  51.                 } else
  52.                 {
  53.                
  54.             $tArr = $option[1];
  55.             $t_r = $tArr[0];
  56.             $t_g = $tArr[1];
  57.             $t_b = $tArr[2];
  58.             $pad = $option[2];
  59.             $avg = round(($r+$b+$g)/3);
  60.        
  61.             if ((abs($r - $t_r) < $pad) && (abs($g - $t_g) < $pad) && (abs($b - $t_b) < $pad))
  62.                 {
  63.                 $r = 255;
  64.                 $g = 255;
  65.                 $b = 255;
  66.                 } else
  67.                 {
  68.                 $r = 0;
  69.                 $g = 0;
  70.                 $b = 0;
  71.                 }
  72.                 }
  73.  
  74.             }
  75.         echo "<div style=\"display:inline-block;vertical-align:center;width:3px;height:3px;background-color:rgba(".$r.", ".$g.", ".$b.", 1);\"></div>";
  76.         }
  77.         echo "</div>";
  78.  
  79.  
  80.        
  81.  
  82.     }
  83.        
  84. }
  85.  
  86. function findArrow($arr, $w, $h, $pad)
  87. {
  88.     $leftVote = 0;
  89.     $rightVote = 0;
  90.     $leftCut = $w / 3.5;
  91.     for ($i=0; $i<$h-1; $i++)
  92.     {
  93.    
  94.         for ($j = 0; $j<$w-1; $j++)
  95.         {
  96.         $r = $arr['c'.$j]['r'.$i]['r'];
  97.         $g = $arr['c'.$j]['r'.$i]['g'];
  98.         $b = $arr['c'.$j]['r'.$i]['b'];
  99.  
  100.        
  101.    
  102.                 if ((abs($r - $b) < $pad) && (abs($r - $g) < $pad) && (abs($g - $b) < $pad) && ($r < 150))
  103.                     {
  104.                     if ($j < $leftCut)
  105.                         {
  106.                         $leftVote++;
  107.                         } else if ($j > $w - $leftCut)
  108.                         {
  109.                         $rightVote++;
  110.                         }
  111.                     $r = 255;
  112.                     $g = 255;
  113.                     $b = 255;
  114.                     }    
  115.                     else
  116.                     {
  117.                     $r = 0;
  118.                     $g = 0;
  119.                     $b = 0;
  120.                     }
  121.                
  122.         }
  123.  
  124.  
  125.  
  126.        
  127.  
  128.     }
  129.        
  130.  
  131.     if ($leftVote > $rightVote)
  132.     {
  133.         return ('left');
  134.     } else if ($leftVote < $rightVote)
  135.     {
  136.         return ('right');
  137.     } else
  138.     {
  139.         return ('none');
  140.     }
  141.    
  142. }
  143. $runBot = true;
  144. $fileNum = 0;
  145. while($runBot)
  146. {
  147.     $time_start = microtime(true);
  148.     $imglist = array();
  149.     foreach ($images as $a => $filename)
  150.     {
  151.        
  152.  
  153.         array_push($imglist, $filename);
  154.     }
  155.     $imgnum = count($imglist);
  156.     $newFilename = $imglist[$imgnum-1];
  157.     $thisImage = 'c:\\rli\\'.$newFilename;
  158.  
  159.     $handle = fopen($thisImage, 'rb');
  160.     $thisImage = new Imagick();
  161.     $thisImage->readImageFile($handle);
  162.  
  163.     $res_W = 300;
  164.  
  165.     $thisImage->scaleImage($res_W, 0);
  166.  
  167.  
  168.     $dim = $thisImage->getImageGeometry();
  169.     $h = $dim['height'];
  170.     $w = $dim['width'];
  171.  
  172.     $cropStart_X = $res_W * 0.425;
  173.  
  174.     $thisImage->cropImage(0.15 * $w, 0.8 * $h, $cropStart_X, 0.7 * $h);
  175.    
  176.  
  177.     $newW = 0.15 * $w;
  178.     $newH = 0.1 * $h;
  179.  
  180.     $circle = new ImagickDraw();
  181.     $circle->setFillColor("#FFFFFF");
  182.     $circle->circle($newW/2,($newH/1.1), ($newW/2.6), ($newH/2.6));
  183.     $thisImage->drawImage($circle);
  184.  
  185.  
  186.     $rArray = $thisImage->exportImagePixels(0, 0, $w, $h, "RGB", Imagick::PIXEL_FLOAT);
  187.  
  188.     $pArray = array();
  189.     $colNum = 0;
  190.     $rowNum = 0;
  191.     for ($i=0; $i<count($rArray); $i += 3)
  192.     {
  193.         if (!isset($pArray['c'.$colNum]))
  194.         {
  195.             $pArray['c'.$colNum] = array();
  196.         }
  197.  
  198.         $pArray['c'.$colNum]['r'.$rowNum] = array('r' => (255 * $rArray[$i]), 'g' => (255 * $rArray[$i+1]), 'b' => (255 * $rArray[$i+2]));
  199.  
  200.         $colNum++;
  201.         if ($colNum > $w-1)
  202.         {
  203.         $rowNum++;
  204.         $colNum = 0;
  205.         } else
  206.         {
  207.         }
  208.        
  209.  
  210.     }
  211.  
  212.  
  213.     drawArray($pArray, $newW, $newH, [null]);
  214.     drawArray($pArray, $newW, $newH, ['select', [150, 150, 150], 20]);
  215.     drawArray($pArray, $newW, $newH, ['select', 'grey', 20]);
  216.     $date = new dateTime();
  217.     $ts = $date->getTimeStamp();
  218.  
  219.  
  220.     $newDir = findArrow($pArray, $newW, $newH, 10);
  221.     echo $newDir."<br>";
  222.  
  223.     $filename = 'C:\\kb\\keybot.txt';
  224.     $update = fopen($filename, "w");
  225.     fwrite($update, $newDir);
  226.     fclose($update);
  227.  
  228.     $time_end = microtime(true);
  229.     $time_script = $time_end - $time_start;
  230. //  echo "script time was ".$time_script;
  231.  
  232.  
  233.  
  234.     $runBot = false;
  235.  
  236.  
  237.    
  238. }
  239.  
  240.  
  241. echo "<script>setTimeout(function(){location.reload();}, 500);</script>";
  242. ?>
Advertisement
Add Comment
Please, Sign In to add comment