mirror of
https://github.com/Intervention/image.git
synced 2025-08-31 09:31:53 +02:00
fixes
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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');
|
||||
|
Reference in New Issue
Block a user