mirror of
https://github.com/Intervention/image.git
synced 2025-08-20 04:31:24 +02:00
fixed issue when cloning Image objects
This commit is contained in:
@@ -43,6 +43,16 @@ abstract class AbstractDriver
|
|||||||
*/
|
*/
|
||||||
abstract protected function coreAvailable();
|
abstract protected function coreAvailable();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns clone of given core
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function cloneCore($core)
|
||||||
|
{
|
||||||
|
return clone $core;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiates new image from given input
|
* Initiates new image from given input
|
||||||
*
|
*
|
||||||
|
@@ -66,4 +66,22 @@ class Driver extends \Intervention\Image\AbstractDriver
|
|||||||
{
|
{
|
||||||
return (extension_loaded('gd') && function_exists('gd_info'));
|
return (extension_loaded('gd') && function_exists('gd_info'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns clone of given core
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function cloneCore($core)
|
||||||
|
{
|
||||||
|
$width = imagesx($core);
|
||||||
|
$height = imagesy($core);
|
||||||
|
$clone = imagecreatetruecolor($width, $height);
|
||||||
|
imagealphablending($clone, false);
|
||||||
|
imagesavealpha($clone, true);
|
||||||
|
|
||||||
|
imagecopy($clone, $core, 0, 0, 0, 0, $width, $height);
|
||||||
|
|
||||||
|
return $clone;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -262,4 +262,12 @@ class Image extends File
|
|||||||
{
|
{
|
||||||
return $this->encoded;
|
return $this->encoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cloning an image
|
||||||
|
*/
|
||||||
|
public function __clone()
|
||||||
|
{
|
||||||
|
$this->core = $this->driver->cloneCore($this->core);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1482,6 +1482,20 @@ class GdSystemTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertColorAtPosition('#939393', $img, 35, 35);
|
$this->assertColorAtPosition('#939393', $img, 35, 35);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCloneImageObject()
|
||||||
|
{
|
||||||
|
$img = $this->manager()->make('tests/images/trim.png');
|
||||||
|
$cln = clone $img;
|
||||||
|
|
||||||
|
// destroy original
|
||||||
|
$img->destroy();
|
||||||
|
unset($img);
|
||||||
|
|
||||||
|
// clone should be still intact
|
||||||
|
$this->assertInstanceOf('Intervention\Image\Image', $cln);
|
||||||
|
$this->assertInternalType('resource', $cln->getCore());
|
||||||
|
}
|
||||||
|
|
||||||
private function assertColorAtPosition($color, $img, $x, $y)
|
private function assertColorAtPosition($color, $img, $x, $y)
|
||||||
{
|
{
|
||||||
$pick = $img->pickColor($x, $y, 'hex');
|
$pick = $img->pickColor($x, $y, 'hex');
|
||||||
|
@@ -1463,6 +1463,20 @@ class ImagickSystemTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCloneImageObject()
|
||||||
|
{
|
||||||
|
$img = $this->manager()->make('tests/images/trim.png');
|
||||||
|
$cln = clone $img;
|
||||||
|
|
||||||
|
// destroy original
|
||||||
|
$img->destroy();
|
||||||
|
unset($img);
|
||||||
|
|
||||||
|
// clone should be still intact
|
||||||
|
$this->assertInstanceOf('Intervention\Image\Image', $cln);
|
||||||
|
$this->assertInstanceOf('Imagick', $cln->getCore());
|
||||||
|
}
|
||||||
|
|
||||||
private function assertColorAtPosition($color, $img, $x, $y)
|
private function assertColorAtPosition($color, $img, $x, $y)
|
||||||
{
|
{
|
||||||
$pick = $img->pickColor($x, $y, 'hex');
|
$pick = $img->pickColor($x, $y, 'hex');
|
||||||
|
Reference in New Issue
Block a user