/** * Downloads and saves multiple images locally. * * @param string $url * @param string $id * @param string/null $path * @param string/int $num * @return void */ public function saveMultiple(array $urls, $id = null, $path) { if (empty($urls)) { return; } $images = $this->scraper->multiCurl($urls); foreach ($images as $k => $v) { //we're saving cast images if (strpos($k, 'nm') || !$id) { try { Imagine::raw($v)->save(public_path($path) . $k . '.jpg', 100); } catch (\Exception $e) { } } else { try { $image = Imagine::raw($v); $image->save(public_path($path) . $id . $k . '.jpg', 60); $image->resize(400, null, function ($constraint) { $constraint->aspectRatio(); })->save(public_path($path) . $id . $k . '.thumb' . '.jpg', 90); } catch (\Exception $e) { } } } }
/** * Scrapes title main page and image page. * * @param Title $model * @return self */ public function getFullTitle(Title $model) { //if model doesn't have imdb_id, bail if (!$model->imdb_id) { return $this; } $this->titleModel = $model; $urls = $this->compileUrls(); $html = $this->scraper->multiCurl($urls); $html['main'] = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $html['main']); $html['imgs'] = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $html['imgs']); $this->crawler = new Crawler($html['main']); $this->imgCrawler = new Crawler($html['imgs']); return $this; }