From f9bd6c102b0a3dff6bfc88396ca60366cc867ec4 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Thu, 11 Dec 2014 15:49:08 +0100 Subject: [PATCH] throw expection on 404 responses when trying to init from url --- src/Intervention/Image/AbstractDecoder.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Intervention/Image/AbstractDecoder.php b/src/Intervention/Image/AbstractDecoder.php index cc268efd..4c49ab90 100644 --- a/src/Intervention/Image/AbstractDecoder.php +++ b/src/Intervention/Image/AbstractDecoder.php @@ -53,6 +53,23 @@ abstract class AbstractDecoder $this->data = $data; } + /** + * Init from fiven URL + * + * @param string $url + * @return \Intervention\Image\Image + */ + public function initFromUrl($url) + { + if ($data = @file_get_contents($url)) { + return $this->initFromBinary($data); + } + + throw new \Intervention\Image\Exception\NotReadableException( + "Unable to init from given url (".$url.")." + ); + } + /** * Determines if current source data is GD resource * @@ -225,7 +242,7 @@ abstract class AbstractDecoder return $this->initFromBinary($this->data); case $this->isUrl(): - return $this->initFromBinary(file_get_contents($this->data)); + return $this->initFromUrl($this->data); case $this->isFilePath(): return $this->initFromPath($this->data);