1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-17 19:26:25 +02:00

added ico and psd write support for imagick driver

This commit is contained in:
Oliver Vogel
2014-11-05 17:45:28 +01:00
parent e626de028b
commit 8d0d2da878
4 changed files with 152 additions and 0 deletions

View File

@@ -67,6 +67,13 @@ abstract class AbstractEncoder
*/
abstract protected function processBmp();
/**
* Processes and returns encoded image as ICO string
*
* @return string
*/
abstract protected function processIco();
/**
* Process a given image
*
@@ -126,6 +133,17 @@ abstract class AbstractEncoder
case 'image/x-xbitmap':
$this->result = $this->processBmp();
break;
case 'ico':
case 'image/x-icon':
case 'image/vnd.microsoft.icon':
$this->result = $this->processIco();
break;
case 'psd':
case 'image/vnd.adobe.photoshop':
$this->result = $this->processPsd();
break;
default:
throw new \Intervention\Image\Exception\NotSupportedException(

View File

@@ -78,4 +78,28 @@ class Encoder extends \Intervention\Image\AbstractEncoder
"BMP format is not supported by Gd Driver."
);
}
/**
* Processes and returns encoded image as ICO string
*
* @return string
*/
protected function processIco()
{
throw new \Intervention\Image\Exception\NotSupportedException(
"ICO format is not supported by Gd Driver."
);
}
/**
* Processes and returns encoded image as PSD string
*
* @return string
*/
protected function processPsd()
{
throw new \Intervention\Image\Exception\NotSupportedException(
"PSD format is not supported by Gd Driver."
);
}
}

View File

@@ -105,4 +105,42 @@ class Encoder extends \Intervention\Image\AbstractEncoder
return $imagick->getImagesBlob();
}
/**
* Processes and returns encoded image as ICO string
*
* @return string
*/
protected function processIco()
{
$format = 'ico';
$compression = \Imagick::COMPRESSION_UNDEFINED;
$imagick = $this->image->getCore();
$imagick->setFormat($format);
$imagick->setImageFormat($format);
$imagick->setCompression($compression);
$imagick->setImageCompression($compression);
return $imagick->getImagesBlob();
}
/**
* Processes and returns encoded image as PSD string
*
* @return string
*/
protected function processPsd()
{
$format = 'psd';
$compression = \Imagick::COMPRESSION_UNDEFINED;
$imagick = $this->image->getCore();
$imagick->setFormat($format);
$imagick->setImageFormat($format);
$imagick->setCompression($compression);
$imagick->setImageCompression($compression);
return $imagick->getImagesBlob();
}
}

View File

@@ -58,6 +58,42 @@ class EncoderTest extends PHPUnit_Framework_TestCase
$this->assertInstanceOf('Intervention\Image\Image', $img);
}
/**
* @expectedException \Intervention\Image\Exception\NotSupportedException
*/
public function testProcessBmpGd()
{
$core = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
$encoder = new GdEncoder;
$image = Mockery::mock('\Intervention\Image\Image');
$img = $encoder->process($image, 'bmp', 90);
$this->assertInstanceOf('Intervention\Image\Image', $img);
}
/**
* @expectedException \Intervention\Image\Exception\NotSupportedException
*/
public function testProcessIcoGd()
{
$core = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
$encoder = new GdEncoder;
$image = Mockery::mock('\Intervention\Image\Image');
$img = $encoder->process($image, 'ico', 90);
$this->assertInstanceOf('Intervention\Image\Image', $img);
}
/**
* @expectedException \Intervention\Image\Exception\NotSupportedException
*/
public function testProcessPsdGd()
{
$core = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
$encoder = new GdEncoder;
$image = Mockery::mock('\Intervention\Image\Image');
$img = $encoder->process($image, 'psd', 90);
$this->assertInstanceOf('Intervention\Image\Image', $img);
}
public function testProcessUnknownWithMimeGd()
{
$core = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
@@ -131,6 +167,42 @@ class EncoderTest extends PHPUnit_Framework_TestCase
$this->assertEquals('mock-tiff', $encoder->result);
}
public function testProcessBmpImagick()
{
$core = $this->getImagickMock('bmp');
$encoder = new ImagickEncoder;
$image = Mockery::mock('\Intervention\Image\Image');
$image->shouldReceive('getCore')->once()->andReturn($core);
$image->shouldReceive('setEncoded')->once()->andReturn($image);
$img = $encoder->process($image, 'bmp', 90);
$this->assertInstanceOf('Intervention\Image\Image', $img);
$this->assertEquals('mock-bmp', $encoder->result);
}
public function testProcessIcoImagick()
{
$core = $this->getImagickMock('ico');
$encoder = new ImagickEncoder;
$image = Mockery::mock('\Intervention\Image\Image');
$image->shouldReceive('getCore')->once()->andReturn($core);
$image->shouldReceive('setEncoded')->once()->andReturn($image);
$img = $encoder->process($image, 'ico', 90);
$this->assertInstanceOf('Intervention\Image\Image', $img);
$this->assertEquals('mock-ico', $encoder->result);
}
public function testProcessPsdImagick()
{
$core = $this->getImagickMock('psd');
$encoder = new ImagickEncoder;
$image = Mockery::mock('\Intervention\Image\Image');
$image->shouldReceive('getCore')->once()->andReturn($core);
$image->shouldReceive('setEncoded')->once()->andReturn($image);
$img = $encoder->process($image, 'psd', 90);
$this->assertInstanceOf('Intervention\Image\Image', $img);
$this->assertEquals('mock-psd', $encoder->result);
}
public function testProcessUnknownWithMimeImagick()
{
$core = $this->getImagickMock('jpeg');