Exemple #1
0
 public function getTestpreg()
 {
     $file = new TFFile();
     $url = 'https://45.media.tumblr.com/e30abb759aaaaa246f4051678dd0697b/tumblr_o2t8a9VzDu1qb6v6ro2_400.gif';
     echo $url;
     echo '<br/>';
     $file->parseImageUrlToHighQuality($url);
     return $file->source;
 }
Exemple #2
0
 protected function sniffImageOfDom(Dom $dom)
 {
     $rawImgSrcs = [];
     // 侦测页面上的img元素
     foreach ($dom->find('img') as $img) {
         $rawImgSrcs[] = $img->getAttribute('src');
     }
     // 侦测iframe内的img元素
     foreach ($dom->find('iframe') as $iframe) {
         $id = $iframe->getAttribute('id');
         if (!strstr($id, 'photoset')) {
             continue;
         }
         $src = $iframe->getAttribute('src');
         $imgDom = $this->requestDom($src);
         foreach ($imgDom->find('img') as $img) {
             $rawImgSrcs[] = $img->getAttribute('src');
         }
     }
     // 过滤所有非用户图片
     $imgSrcs = [];
     foreach ($rawImgSrcs as $rawImgSrc) {
         $isGood = true;
         foreach ($this->imgExceptWords as $except) {
             if (strstr($rawImgSrc, $except)) {
                 $isGood = false;
             }
         }
         if ($isGood) {
             $imgSrcs[] = $rawImgSrc;
         }
     }
     // 保存
     foreach ($imgSrcs as $imgSrc) {
         $srcExplode = explode('/', $imgSrc);
         $name = array_pop($srcExplode);
         if (TFFile::where('name', '=', $name)->count() != 0) {
             continue;
         }
         $image = new TFFile();
         $image->type = 'image';
         $image->state = 'sniffed';
         $image->error = '';
         $image->name = $name;
         $image->parseImageUrlToHighQuality($imgSrc);
         $image->save();
     }
 }