diff --git a/README.md b/README.md index fcb3493..d123165 100644 --- a/README.md +++ b/README.md @@ -417,7 +417,7 @@ $movie = Tmdb::client('API_KEY') ->movies() ->details(movie_id: 120); // ?\Kiwilan\Tmdb\Models\Movie -$poster_url = $movie->getPosterUrl(size: PosterSize::W500); // string|null (url to poster) +$poster_url = $movie->getPosterUrl(size: PosterSize::W500); // string|null (URL to poster) ``` These methods are available for `Poster`, `Backdrop`, `Logo`, `Profile` and `Still`. diff --git a/src/Utils/TmdbImage.php b/src/Utils/TmdbImage.php index d7286de..d81c072 100644 --- a/src/Utils/TmdbImage.php +++ b/src/Utils/TmdbImage.php @@ -32,11 +32,12 @@ public function getUrl(): string /** * Get the image content, as binary. */ - public function getImage(): string + public function getImage(): ?string { $url = $this->getUrl(); + $contents = file_get_contents($url); - return file_get_contents($url); + return $contents !== false ? $contents : null; } /** @@ -45,6 +46,9 @@ public function getImage(): string public function saveImage(string $path): bool { $contents = $this->getImage(); + if ($contents === null) { + return false; + } return file_put_contents($path, $contents) !== false; }