Exemplo n.º 1
0
 /**
  * Get PHash
  */
 public function getPHash()
 {
     $content = file_get_contents($this->url);
     $tempFile = Yii::getAlias('@app/runtime/' . time() . mt_rand(0, 1000));
     file_put_contents($tempFile, $content);
     $hash = ImageManager::getPHash($tempFile);
     unlink($tempFile);
     return $hash;
 }
Exemplo n.º 2
0
 /**
  * Import files from directory
  * @throws \yii\base\Exception
  */
 public function actionIndex()
 {
     $finder = new Finder();
     $iterator = $finder->files()->name('*.jpg')->name('*.jpeg')->name('*.png')->size('>= 10K')->size('<= 1M')->in(realpath($this->directory));
     $i = 1;
     foreach ($iterator as $file) {
         /** @var Image $image */
         $image = ImageManager::importImage($file->getRealpath());
         if ($image) {
             printf("[%d/%d] %s %s\n", $i, $iterator->count(), $file->getRealpath(), $image->phash);
         } else {
             printf("[%d/%d] Skipped\n", $i, $iterator->count());
         }
         $i++;
     }
 }
Exemplo n.º 3
0
 /**
  * Get PHash
  */
 public function getPHash()
 {
     return ImageManager::getPHash($this->imageFile->tempName);
 }