mirror of
https://github.com/Intervention/image.git
synced 2025-08-13 17:34:04 +02:00
added static method canvas
This commit is contained in:
13
README.md
13
README.md
@@ -42,8 +42,9 @@ Add the facade of this package to the `$aliases` array.
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
* Image::__construct - Create new instance of Image class
|
* Image::__construct - Create new instance of Image class
|
||||||
* Image::make - Create new image resource from image file
|
* Image::make - Open a new image resource from image file or create a new empty image
|
||||||
* Image::resize - Resize image based on given width and/or height
|
* Image::canvas - Create a new empty image resource
|
||||||
|
* Image::resize - Resize current image based on given width and/or height
|
||||||
* Image::grab - Cut out a detail of the image in given ratio and resize to output size
|
* Image::grab - Cut out a detail of the image in given ratio and resize to output size
|
||||||
* Image::insert - Insert another image on top of the current image
|
* Image::insert - Insert another image on top of the current image
|
||||||
* Image::brightness - Changes brightness of current image
|
* Image::brightness - Changes brightness of current image
|
||||||
@@ -64,6 +65,9 @@ Add the facade of this package to the `$aliases` array.
|
|||||||
### Code example (Laravel)
|
### Code example (Laravel)
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
// create an empty Image resource (background color transparent)
|
||||||
|
$img = Image::canvas(640, 480);
|
||||||
|
|
||||||
// create Image from file
|
// create Image from file
|
||||||
$img = Image::make('public/foo.jpg');
|
$img = Image::make('public/foo.jpg');
|
||||||
|
|
||||||
@@ -103,12 +107,9 @@ $img->save('public/bar.jpg');
|
|||||||
$img->save('public/bar.jpg', 60);
|
$img->save('public/bar.jpg', 60);
|
||||||
|
|
||||||
// its also possible to chain methods
|
// its also possible to chain methods
|
||||||
$img1 = Image::make('public/img1.png');
|
$img1 = Image::canvas(800, 600);
|
||||||
$img2 = Image::make('public/img2.png');
|
$img2 = Image::make('public/img2.png');
|
||||||
$img1->resize(300, 200)->insert($img2)->save('public/bar.jpg');
|
$img1->resize(300, 200)->insert($img2)->save('public/bar.jpg');
|
||||||
|
|
||||||
// create an empty (transparent background) image, without opening any file
|
|
||||||
$img = new Image(null, 300, 200);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
@@ -73,7 +73,7 @@ class Image
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new image resource from image file
|
* Open a new image resource from image file or create a new empty image
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @return Image
|
* @return Image
|
||||||
@@ -83,6 +83,18 @@ class Image
|
|||||||
return new Image($path, $width, $height);
|
return new Image($path, $width, $height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new empty image resource
|
||||||
|
*
|
||||||
|
* @param int $width
|
||||||
|
* @param int $height
|
||||||
|
* @return Image
|
||||||
|
*/
|
||||||
|
public static function canvas($width, $height)
|
||||||
|
{
|
||||||
|
return new Image(null, $width, $height);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set local properties for image resource
|
* Set local properties for image resource
|
||||||
*
|
*
|
||||||
|
@@ -361,4 +361,42 @@ class ImageTest extends PHPUnit_Framework_Testcase
|
|||||||
$img->contrast(-50);
|
$img->contrast(-50);
|
||||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testStaticCallMake()
|
||||||
|
{
|
||||||
|
$img = Image::make('public/test.jpg');
|
||||||
|
$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);
|
||||||
|
$this->assertEquals($img->dirname, 'public');
|
||||||
|
$this->assertEquals($img->basename, 'test.jpg');
|
||||||
|
$this->assertEquals($img->extension, 'jpg');
|
||||||
|
$this->assertEquals($img->filename, 'test');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testStaticCallCanvas()
|
||||||
|
{
|
||||||
|
$img = Image::canvas(300, 200);
|
||||||
|
$this->assertInternalType('resource', $img->resource);
|
||||||
|
$this->assertInternalType('int', $img->width);
|
||||||
|
$this->assertInternalType('int', $img->height);
|
||||||
|
$this->assertEquals($img->width, 300);
|
||||||
|
$this->assertEquals($img->height, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateCanvasWithTransparentBackground()
|
||||||
|
{
|
||||||
|
$img = Image::canvas(100, 100);
|
||||||
|
$color = $img->pickColor(50, 50, 'array');
|
||||||
|
$this->assertInternalType('int', $color['red']);
|
||||||
|
$this->assertInternalType('int', $color['green']);
|
||||||
|
$this->assertInternalType('int', $color['blue']);
|
||||||
|
$this->assertInternalType('int', $color['alpha']);
|
||||||
|
$this->assertEquals($color['red'], 0);
|
||||||
|
$this->assertEquals($color['green'], 0);
|
||||||
|
$this->assertEquals($color['blue'], 0);
|
||||||
|
$this->assertEquals($color['alpha'], 127);
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user