I have code like this in a function:   function stacklayer($folder, $layer) {        $newlayer = imagecreatefrompng($folder . '/' . $layer . '.png');         imagecopy($baseimage,$newlayer,0,0,0,0,$w,$h);         imagedestroy($newlayer);  } stacklayer('Layer1', 'Image1') But $baseimage does not have the new layers added on top of $baseimage created outside the function.  In this manner: $baseimage = imagecreatefrompng("Base.png"); $w = imagesx($baseimage); $