1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-31 09:31:53 +02:00
This commit is contained in:
Oliver Vogel
2014-05-12 17:26:33 +02:00
parent 40d9265123
commit 5b7ab0d190
5 changed files with 24 additions and 7 deletions

View File

@@ -18,6 +18,10 @@ class File
$this->extension = array_key_exists('extension', $info) ? $info['extension'] : null;
$this->filename = array_key_exists('filename', $info) ? $info['filename'] : null;
if (file_exists($path)) {
$this->mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);
}
return $this;
}
}

View File

@@ -58,6 +58,16 @@ class ResizeCanvasCommand extends \Intervention\Image\Commands\AbstractCommand
$src_h = $original_height;
}
// make image area transparent to keep transparency
// even if background-color is set
$rect = new \ImagickDraw;
$fill = $canvas->pickColor(0, 0, 'hex');
$fill = $fill == '#ff0000' ? '#00ff00' : '#ff0000';
$rect->setFillColor($fill);
$rect->rectangle($dst_x, $dst_y, $dst_x + $src_w - 1, $dst_y + $src_h - 1);
$canvas->getCore()->drawImage($rect);
$canvas->getCore()->paintTransparentImage($fill, 0, 0);
// copy image into new canvas
$image->getCore()->cropImage($src_w, $src_h, $src_x, $src_y);
$canvas->getCore()->compositeImage($image->getCore(), \Imagick::COMPOSITE_DEFAULT, $dst_x, $dst_y);

View File

@@ -24,7 +24,6 @@ class Source extends \Intervention\Image\AbstractSource
// build image
$image = $this->initFromImagick($core);
$image->mime = $this->getMime($core);
$image->setFileInfoFromPath($path);
return $image;

View File

@@ -7,10 +7,11 @@ class FileTest extends PHPUnit_Framework_TestCase
public function testSetFileInfoFromPath()
{
$file = new File;
$file->setFileInfoFromPath('test/foo/bar.baz');
$this->assertEquals('test/foo', $file->dirname);
$this->assertEquals('bar.baz', $file->basename);
$this->assertEquals('baz', $file->extension);
$this->assertEquals('bar', $file->filename);
$file->setFileInfoFromPath('tests/images/test.jpg');
$this->assertEquals('tests/images', $file->dirname);
$this->assertEquals('test.jpg', $file->basename);
$this->assertEquals('jpg', $file->extension);
$this->assertEquals('test', $file->filename);
$this->assertEquals('image/jpeg', $file->mime);
}
}

View File

@@ -54,9 +54,12 @@ class ResizeCanvasCommandTest extends PHPUnit_Framework_TestCase
$imagick->shouldReceive('cropimage')->with(800, 600, 0, 0)->once();
$imagick->shouldReceive('compositeimage')->with($imagick, 40, 0, 0)->once();
$imagick->shouldReceive('setimagepage')->with(0, 0, 0, 0)->once();
$imagick->shouldReceive('drawimage')->once();
$imagick->shouldReceive('painttransparentimage')->once();
$canvas->shouldReceive('getCore')->times(3)->andReturn($imagick);
$canvas->shouldReceive('getCore')->times(5)->andReturn($imagick);
$canvas->shouldReceive('getSize')->andReturn($canvas_size);
$canvas->shouldReceive('pickColor')->with(0, 0, 'hex')->once()->andReturn('#000000');
$driver = Mockery::mock('\Intervention\Image\Gd\Driver');
$driver->shouldReceive('newImage')->with(820, 640, '#b53717')->once()->andReturn($canvas);
$image = Mockery::mock('Intervention\Image\Image');