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?