1
0
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:
Oliver Vogel
2013-02-04 18:07:42 +01:00
parent db1fb01f9c
commit 27bbfb0c1b
3 changed files with 58 additions and 7 deletions

View File

@@ -42,8 +42,9 @@ Add the facade of this package to the `$aliases` array.
## Usage
* Image::__construct - Create new instance of Image class
* Image::make - Create new image resource from image file
* Image::resize - Resize image based on given width and/or height
* Image::make - Open a new image resource from image file or create a new empty image
* 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::insert - Insert another image on top of the 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)
```php
// create an empty Image resource (background color transparent)
$img = Image::canvas(640, 480);
// create Image from file
$img = Image::make('public/foo.jpg');
@@ -103,12 +107,9 @@ $img->save('public/bar.jpg');
$img->save('public/bar.jpg', 60);
// its also possible to chain methods
$img1 = Image::make('public/img1.png');
$img1 = Image::canvas(800, 600);
$img2 = Image::make('public/img2.png');
$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

View File

@@ -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
* @return Image
@@ -83,6 +83,18 @@ class Image
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
*

View File

@@ -361,4 +361,42 @@ class ImageTest extends PHPUnit_Framework_Testcase
$img->contrast(-50);
$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);
}
}