mirror of
https://github.com/Intervention/image.git
synced 2025-01-18 04:38:26 +01:00
added possibility to create image from gd resource
This commit is contained in:
parent
d4ebd42853
commit
92cb637475
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user