mirror of
https://github.com/Intervention/image.git
synced 2025-08-18 03:31:19 +02:00
added ico and psd write support for imagick driver
This commit is contained in:
@@ -67,6 +67,13 @@ abstract class AbstractEncoder
|
|||||||
*/
|
*/
|
||||||
abstract protected function processBmp();
|
abstract protected function processBmp();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes and returns encoded image as ICO string
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
abstract protected function processIco();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process a given image
|
* Process a given image
|
||||||
*
|
*
|
||||||
@@ -126,6 +133,17 @@ abstract class AbstractEncoder
|
|||||||
case 'image/x-xbitmap':
|
case 'image/x-xbitmap':
|
||||||
$this->result = $this->processBmp();
|
$this->result = $this->processBmp();
|
||||||
break;
|
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:
|
default:
|
||||||
throw new \Intervention\Image\Exception\NotSupportedException(
|
throw new \Intervention\Image\Exception\NotSupportedException(
|
||||||
|
@@ -78,4 +78,28 @@ class Encoder extends \Intervention\Image\AbstractEncoder
|
|||||||
"BMP format is not supported by Gd Driver."
|
"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."
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -105,4 +105,42 @@ class Encoder extends \Intervention\Image\AbstractEncoder
|
|||||||
|
|
||||||
return $imagick->getImagesBlob();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -58,6 +58,42 @@ class EncoderTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
$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()
|
public function testProcessUnknownWithMimeGd()
|
||||||
{
|
{
|
||||||
$core = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
|
$core = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
|
||||||
@@ -131,6 +167,42 @@ class EncoderTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('mock-tiff', $encoder->result);
|
$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()
|
public function testProcessUnknownWithMimeImagick()
|
||||||
{
|
{
|
||||||
$core = $this->getImagickMock('jpeg');
|
$core = $this->getImagickMock('jpeg');
|
||||||
|
Reference in New Issue
Block a user