mirror of
https://github.com/Intervention/image.git
synced 2025-08-18 19:51:22 +02:00
added option to reset an "empty" image
This commit is contained in:
@@ -70,6 +70,13 @@ class Image
|
|||||||
*/
|
*/
|
||||||
protected $filesystem;
|
protected $filesystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attributes of the original created image
|
||||||
|
*
|
||||||
|
* @var Array
|
||||||
|
*/
|
||||||
|
protected $original;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance of Image class
|
* Create a new instance of Image class
|
||||||
*
|
*
|
||||||
@@ -152,6 +159,9 @@ class Image
|
|||||||
$this->width = is_numeric($width) ? intval($width) : 1;
|
$this->width = is_numeric($width) ? intval($width) : 1;
|
||||||
$this->height = is_numeric($height) ? intval($height) : 1;
|
$this->height = is_numeric($height) ? intval($height) : 1;
|
||||||
|
|
||||||
|
$this->original['width'] = $this->width;
|
||||||
|
$this->original['height'] = $this->height;
|
||||||
|
|
||||||
// create empty image
|
// create empty image
|
||||||
$this->resource = @imagecreatetruecolor($this->width, $this->height);
|
$this->resource = @imagecreatetruecolor($this->width, $this->height);
|
||||||
|
|
||||||
@@ -593,7 +603,14 @@ class Image
|
|||||||
*/
|
*/
|
||||||
public function reset()
|
public function reset()
|
||||||
{
|
{
|
||||||
$this->setProperties($this->dirname .'/'. $this->basename);
|
if (is_null($this->dirname) && is_null($this->basename)) {
|
||||||
|
|
||||||
|
$this->setProperties(null, $this->original['width'], $this->original['height']);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$this->setProperties($this->dirname .'/'. $this->basename);
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -742,7 +759,7 @@ class Image
|
|||||||
{
|
{
|
||||||
$path = is_null($path) ? ($this->dirname .'/'. $this->basename) : $path;
|
$path = is_null($path) ? ($this->dirname .'/'. $this->basename) : $path;
|
||||||
file_put_contents($path, $this->data($this->filesystem->extension($path), $quality));
|
file_put_contents($path, $this->data($this->filesystem->extension($path), $quality));
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -290,6 +290,17 @@ class ImageTest extends PHPUnit_Framework_Testcase
|
|||||||
$this->assertEquals($img->height, 600);
|
$this->assertEquals($img->height, 600);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testResetEmptyImage()
|
||||||
|
{
|
||||||
|
$img = new Image(null, 800, 600);
|
||||||
|
$img->resize(300, 200);
|
||||||
|
$img->reset();
|
||||||
|
$this->assertInternalType('int', $img->width);
|
||||||
|
$this->assertInternalType('int', $img->height);
|
||||||
|
$this->assertEquals($img->width, 800);
|
||||||
|
$this->assertEquals($img->height, 600);
|
||||||
|
}
|
||||||
|
|
||||||
public function testSaveImage()
|
public function testSaveImage()
|
||||||
{
|
{
|
||||||
$save_as = 'public/test2.jpg';
|
$save_as = 'public/test2.jpg';
|
||||||
|
Reference in New Issue
Block a user