Advertisement
Guest User

Untitled

a guest
Jan 28th, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.44 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: zheev
  5.  * Date: 26.01.18
  6.  * Time: 0:49
  7.  */
  8.  
  9. echo '<form action="/" enctype="multipart/form-data" method="post">
  10.        <input type="file" name="foto" />
  11.        <input type="submit" name="submit" />
  12.    </form>';
  13.  
  14. $mime = [
  15.     'image/png',
  16.     'image/jpeg',
  17.     'image/jpeg',
  18.     'image/jpg',
  19.     'image/gif',
  20.     'image/bmp',
  21.     'image/vnd.microsoft.icon',
  22.     'image/tiff',
  23.     'image/tiff',
  24.     'image/svg+xml',
  25.     'image/svg+xml',
  26. ];
  27.  
  28. if($_POST['submit'])
  29. {
  30.  
  31.     $sum = 0;
  32.  
  33.     $name = $_FILES['foto']['tmp_name'];
  34.  
  35.     $sizes = getimagesize($name);
  36.  
  37.     if(in_array($sizes['mime'], $mime))
  38.     {
  39.         $type = explode('/', $sizes['mime']);
  40.  
  41.         if($type[1] == 'png')
  42.         {
  43.  
  44.             $photo = imagecreatefrompng($name);
  45.  
  46.         }elseif($type[1] == 'jpeg')
  47.         {
  48.  
  49.             $photo = imagecreatefromjpeg($name);
  50.  
  51.         }
  52.  
  53.  
  54.         for($w = 0; $w <= $sizes[0]; $w++)
  55.         {
  56.  
  57.             for($h=0; $h <= $sizes[1]; $h++)
  58.             {
  59.                 $color = imagecolorat($photo, $w, $h);
  60.                 // получаем цвета
  61.                 $arr_col = imagecolorsforindex($photo, $color);
  62.  
  63.                 if($arr_col['red'] == 255 and $arr_col['green'] == 255 and $arr_col['blue'] == 255)
  64.                 {
  65.                     $sum = $sum + 1;
  66.                 }
  67.             }
  68.  
  69.         }
  70.  
  71.         echo $sum;
  72.     }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement