Advertisement
PifyZ

Compter les points

Jul 6th, 2014
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  1. <?php
  2. if (isset($_FILES['img'], $_POST['send'])) {
  3.     move_uploaded_file($_FILES['img']['tmp_name'], 'img.png');
  4.  
  5.     $total = 0;
  6.  
  7.     if ($image = imagecreatefrompng('img.png')){
  8.         $infos = getimagesize('img.png');
  9.  
  10.         for ($i = 0 ; $i < $infos[1] / 10 - 1 ; $i++) {
  11.             for ($j = 0 ; $j < $infos[0] / 10 - 1 ; $j++) {
  12.                 $rgb = imagecolorat($image, 5 + 10 * $j, 5 + 10 * $i);
  13.  
  14.                 $r = ($rgb >> 16) & 0xFF;
  15.                 $v = ($rgb >> 8) & 0xFF;
  16.  
  17.                 if (in_array($r, [ 255, 143, 82 ]) && in_array($v, [ 255, 143, 82 ])) {
  18.                     $total++;
  19.                 }
  20.             }
  21.         }
  22.     } else {
  23.         echo 'Un vrai PNG serait le bienvenue, merci pour l\'erreur é_è<br/>';
  24.     }
  25.  
  26.     if ($total > 0) {
  27.         echo 'Sur la dernière image uploadée, il y a ' . $total . ' points. (si c\'est une image correcte !)';
  28.     } else {
  29.         echo 'La dernière image semble totalement invalide !';
  30.     }
  31. }
  32. ?>
  33.  
  34. <form method="post" action="index.php" enctype="multipart/form-data">
  35.     <input type="file" name="img" />
  36.     <input type="submit" name="send" value="Envoyer" />
  37. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement