Assinging a GD reference to a new variable fails to copy
Posted
by Stomped
on Stack Overflow
See other posts from Stack Overflow
or by Stomped
Published on 2010-03-11T04:13:24Z
Indexed on
2010/03/11
4:39 UTC
Read the original article
Hit count: 518
This is a contrived example, but it illustrates my problem much more concisely then the code I'm using - and I've tested this and it exhibits the problem:
$image = imagecreatefromjpeg('test.jpg');
$copy_of_image = $image;
// The important bit
imagedestroy($image);
header('Content-type: image/jpeg');
imagejpeg($copy_of_image);
Now, my expectation is that $copy_of_image
is exactly that, but when I run this, it fails, printing out the URL of the script of all things. Comment out the imagedestroy()
and it works just fine.
a var_dump of $image provides:
resource(3) of type (gd)
So why can't I copy this? Apparently the assignment $copy_of_image = $image
is creating a reference rather then a copy - is there a way to prevent that?
© Stack Overflow or respective owner