diff --git a/src/Intervention/Image/Image.php b/src/Intervention/Image/Image.php index 9581ddf0..84852b08 100644 --- a/src/Intervention/Image/Image.php +++ b/src/Intervention/Image/Image.php @@ -87,17 +87,21 @@ class Image /** * Create a new instance of Image class * - * @param string $path + * @param string $source * @param integer $width * @param integer $height * @param mixed $bgcolor */ - public function __construct($path = null, $width = null, $height = null, $bgcolor = null) + public function __construct($source = null, $width = null, $height = null, $bgcolor = null) { // set image properties - if ( ! is_null($path)) { + if ( ! is_null($source)) { - $this->setPropertiesFromPath($path); + if (is_resource($source)) { + $this->setPropertiesFromResource($source); + } else { + $this->setPropertiesFromPath($source); + } } else { @@ -108,13 +112,18 @@ class Image /** * Open a new image resource from image file * - * @param string $path + * @param mixed $source * @return Image */ - public static function make($path) + public static function make($source) { $image = new Image; - $image->setPropertiesFromPath($path); + + if (is_resource($source)) { + $image->setPropertiesFromResource($source); + } else { + $image->setPropertiesFromPath($source); + } return $image; } diff --git a/tests/ImageTest.php b/tests/ImageTest.php index 09f795f3..e3aaa4a5 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -41,6 +41,15 @@ class ImageTest extends PHPUnit_Framework_Testcase $this->assertInternalType('int', $img->height); $this->assertEquals($img->width, 800); $this->assertEquals($img->height, 600); + + $resource = imagecreatefromjpeg('public/test.jpg'); + $img = new Image($resource); + $this->assertInstanceOf('Intervention\Image\Image', $img); + $this->assertInternalType('resource', $img->resource); + $this->assertInternalType('int', $img->width); + $this->assertInternalType('int', $img->height); + $this->assertEquals($img->width, 800); + $this->assertEquals($img->height, 600); } public function testOpenImage() @@ -1040,6 +1049,17 @@ class ImageTest extends PHPUnit_Framework_Testcase $this->assertEquals($img->mime, 'image/jpeg'); } + public function testStaticCallMakeFromResource() + { + $resource = imagecreatefromjpeg('public/test.jpg'); + $img = Image::make($resource); + $this->assertInternalType('resource', $img->resource); + $this->assertInternalType('int', $img->width); + $this->assertInternalType('int', $img->height); + $this->assertEquals($img->width, 800); + $this->assertEquals($img->height, 600); + } + public function testStaticCallCanvas() { $img = Image::canvas(300, 200);