Fix problem Image resource cloning#1329
Conversation
|
@mzk Can you explain why this is needed? |
|
@enumag : Sure. $original = \Nette\Image::fromFile('http://files.nette.org/images/logo.png');
$clone = clone $original;
$clone->filter(IMG_FILTER_GRAYSCALE); //Methods affect the original image :/
echo '<img src="data:image/png;base64,'.base64_encode($clone->toString(\Nette\Image::PNG, 90)).'" />';
echo '<img src="data:image/png;base64,'.base64_encode($original->toString(\Nette\Image::PNG, 90)).'" />'; //grayscaleNow i find old topic with same: http://forum.nette.org/cs/2832-clone-nette-image If i try for example method |
|
@mzk I see. Some methods create new resource but others only modifies the old one. 👍 for this |
There was a problem hiding this comment.
Other methods are using $this->image = ... instead of setImageResource(...) - should be consistent. It's not the same case with getImageResource() though.
|
new commit (new line to end file, remove duplicate test, remove comment) |
|
@mzk Squash them both into one commit and force-push. |
|
👍 |
|
What about non-truecolor images? Maybe the simplest solution is imagecreatefromstring + imagegd2 + output buffering… |
|
Before I send another commit, you mean like this? public function __clone()
{
//$clonedResource = imagecreatetruecolor($this->getWidth(), $this->getHeight());
$clonedResource = imagecreatefromstring($this->toString());
imagecopymerge($clonedResource, $this->getImageResource(), 0, 0, 0, 0, $this->getWidth(), $this->getHeight(), 100);
$this->setImageResource($clonedResource);
}maybe public function __clone()
{
//$clonedResource = imagecreatetruecolor($this->getWidth(), $this->getHeight());
$clonedResource = imagecreatefromstring($this->toString());
$this->setImageResource($clonedResource);
}output buffering = method toString() |
|
I think (hope) imagegd2 is native and really lossless format. |
|
I think it is 32b per pixel (rgba). Using compressed flag might save some space. It is just binary packing not actual compression. |
|
Compressed flag might be even slightly faster for truecolor images. Pixel is set using addition and binary shifts instead of function call. |
No description provided.