Duplicate a image variable GD library

杀马特。学长 韩版系。学妹 提交于 2019-12-01 20:36:49

The reason your try didn't work is because the variable only stores a handle (a memory pointer) to the GD image. Both $varnew and $varold will still store the same pointer, thus pointing to the exact same image in memory. You have to use imagecopy or, maybe worse, open the image from file again.

You can use imagecopy

Use This:

function cloneImg($img){
    //get dimensions
    $w = imagesx($img);
    $h = imagesy($img);
     //copy process
    $copy = imagecreatetruecolor($w, $h);
    imagecopy($copy, $img, 0, 0, 0, 0, $w, $h);

    return $copy;

  }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!