1
0
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:
Oliver Vogel
2014-08-21 20:33:25 +02:00
parent 0d6d0ab312
commit a912b12ede
2 changed files with 30 additions and 1 deletions

View File

@@ -79,7 +79,14 @@ class Image extends File
*/
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);
$saved = @file_put_contents($path, $data);
@@ -253,6 +260,20 @@ class Image extends File
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
*

View File

@@ -57,6 +57,12 @@ class ImageTest extends PHPUnit_Framework_TestCase
$this->assertEquals('image/png', $image->mime());
}
public function testBasePath()
{
$image = $this->getTestImage();
$this->assertEquals('./tmp/foo.png', $image->basePath());
}
private function getTestImage()
{
$size = Mockery::mock('\Intervention\Image\Size', array(800, 600));
@@ -67,6 +73,8 @@ class ImageTest extends PHPUnit_Framework_TestCase
$driver->shouldReceive('executeCommand')->andReturn($command);
$image = new Image($driver, 'mock');
$image->mime = 'image/png';
$image->dirname = './tmp';
$image->basename = 'foo.png';
return $image;
}