mirror of
https://github.com/Intervention/image.git
synced 2025-08-26 15:24:37 +02:00
added Image::basePath()
This commit is contained in:
@@ -79,7 +79,14 @@ class Image extends File
|
|||||||
*/
|
*/
|
||||||
public function save($path = null, $quality = null)
|
public function save($path = null, $quality = null)
|
||||||
{
|
{
|
||||||
$path = is_null($path) ? ($this->dirname .'/'. $this->basename) : $path;
|
$path = is_null($path) ? $this->basePath() : $path;
|
||||||
|
|
||||||
|
if (is_null($path)) {
|
||||||
|
throw new Exception\NotWritableException(
|
||||||
|
"Can't write to undefined path."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$data = $this->encode(pathinfo($path, PATHINFO_EXTENSION), $quality);
|
$data = $this->encode(pathinfo($path, PATHINFO_EXTENSION), $quality);
|
||||||
$saved = @file_put_contents($path, $data);
|
$saved = @file_put_contents($path, $data);
|
||||||
|
|
||||||
@@ -253,6 +260,20 @@ class Image extends File
|
|||||||
return $this->mime;
|
return $this->mime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get fully qualified path to image
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function basePath()
|
||||||
|
{
|
||||||
|
if ($this->dirname && $this->basename) {
|
||||||
|
return ($this->dirname .'/'. $this->basename);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns encoded image data in string conversion
|
* Returns encoded image data in string conversion
|
||||||
*
|
*
|
||||||
|
@@ -57,6 +57,12 @@ class ImageTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('image/png', $image->mime());
|
$this->assertEquals('image/png', $image->mime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testBasePath()
|
||||||
|
{
|
||||||
|
$image = $this->getTestImage();
|
||||||
|
$this->assertEquals('./tmp/foo.png', $image->basePath());
|
||||||
|
}
|
||||||
|
|
||||||
private function getTestImage()
|
private function getTestImage()
|
||||||
{
|
{
|
||||||
$size = Mockery::mock('\Intervention\Image\Size', array(800, 600));
|
$size = Mockery::mock('\Intervention\Image\Size', array(800, 600));
|
||||||
@@ -67,6 +73,8 @@ class ImageTest extends PHPUnit_Framework_TestCase
|
|||||||
$driver->shouldReceive('executeCommand')->andReturn($command);
|
$driver->shouldReceive('executeCommand')->andReturn($command);
|
||||||
$image = new Image($driver, 'mock');
|
$image = new Image($driver, 'mock');
|
||||||
$image->mime = 'image/png';
|
$image->mime = 'image/png';
|
||||||
|
$image->dirname = './tmp';
|
||||||
|
$image->basename = 'foo.png';
|
||||||
|
|
||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user