/**
  * Отримати заповнене полотно
  * @return Canvas
  */
 public static function getCanvas()
 {
     set_time_limit(60);
     $setting = SettingsForm::instance();
     $canvas = new Canvas($setting->count, $setting->countHeight, $setting->countWidth);
     /** @var User $user */
     $user = \Yii::$app->user->getIdentity();
     $count = $canvas->getCountPictures();
     $pictureCurrent = 0;
     $pictures = [];
     $colorPictures = [];
     $color = new Color();
     for ($i = $count; $i > 0;) {
         if (empty($colorPictures)) {
             $colorPictures = $user->getInstagram()->getPhotos();
             if (empty($colorPictures)) {
                 break;
             }
         }
         $colorPicture = array_shift($colorPictures);
         if ($setting->color) {
             $color->setAddress($colorPicture->images->thumbnail->url);
             if ($color->hasDominantColor($setting->color)) {
                 $colorPicture = $colorPicture;
             } else {
                 $colorPicture = null;
             }
         }
         if ($colorPicture) {
             $pictures[] = $colorPicture;
             --$i;
         }
     }
     if (empty($pictures)) {
         return $canvas;
     }
     /** @var Row $canvasRow */
     foreach ($canvas as $canvasRow) {
         /** @var Picture $row */
         foreach ($canvasRow as $row) {
             if (!isset($pictures[$pictureCurrent])) {
                 if ($setting->repeat) {
                     $picture = $pictures[array_rand($pictures)];
                 } else {
                     break;
                 }
             } else {
                 $picture = $pictures[$pictureCurrent];
                 ++$pictureCurrent;
             }
             $row->setUrl($picture->images->thumbnail->url);
         }
     }
     $user->getInstagram()->rewindPhoto();
     return $canvas;
 }
 public function actionTest()
 {
     $i = 10;
     $g = 20;
     $photo = new GeneratorImageColorPalette();
     //        $t1 = $photo->getImageColor('https://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-15/s150x150/e35/11820536_519767031505386_1692984693_n.jpg',$i,$g);
     //        $t2 = $photo->getImageColor('https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e35/11850151_147906375552698_1188110438_n.jpg',$i,$g);
     //        $t3 = $photo->getImageColor('https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e35/11850151_147906375552698_1188110438_n.jpg',$i,$g);
     //        $t4 = $photo->getImageColor('https://scontent.cdninstagram.com/hphotos-xfp1/t51.2885-15/s150x150/e35/1389277_898236996891339_792704999_n.jpg',$i,$g);
     //        $t5 = $photo->getImageColor('https://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-15/s150x150/e35/11375282_1475416576086732_1622940988_n.jpg',$i,$g);
     $t = 'https://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-15/s150x150/e35/11375282_1475416576086732_1622940988_n.jpg';
     //        $t = 'https://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-15/s150x150/e35/11820536_519767031505386_1692984693_n.jpg';
     //        $t = 'https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e35/11850151_147906375552698_1188110438_n.jpg';
     $t = 'https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e15/11325634_802930826488058_1599582105_n.jpg';
     $t = 'https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e15/11382549_922947047728394_1720425873_n.jpg';
     $t = 'https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e15/11287495_1640746426170859_1360888926_n.jpg';
     $t = 'https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e15/11358192_686709151434224_172548493_n.jpg';
     //        $t = 'https://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-15/s150x150/e35/11820536_519767031505386_1692984693_n.jpg';
     //        $t = 'https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e35/c216.0.648.648/11950711_476949739149891_1670913693_n.jpg';
     //Загрузка JPG-изображения из файла Image.jpg
     $image = imageCreateFromJpeg($t);
     //Возвращаем цвет пикселя с координатами (10, 15) на изображении $image
     $color = imagecolorat($image, 10, 15);
     $colors = imagecolorsforindex($image, $color);
     //Получаем составляющие цвета (red, green, blue)
     //        $r = ($color >> 16) & 0xFF;
     //        $g = ($color >> 8) & 0xFF;
     //        $b = $color & 0xFF;
     //Выводим результат
     //        echo $r."<br />";
     //        echo $g."<br />";
     //        echo $b."<br />";
     //
     var_dump($colors);
     var_dump(max(array(5 => 88, 99 => 55)));
     //Освобождаем ресурсы сервера
     //        imageDestroy($image);
     $t = new Color($t);
     echo $t->getDominantColor();
 }