dswsl2016 2012-09-26 15:57
浏览 10
已采纳

如何在PHP中克隆gd资源

I'm looking for cloning an image in PHP created with imagecreatetruecolor or some other image creation function..

As it was said in the comment, no you can't do a simple affection like :

$copy = $original;

This because ressources are reference and could not be copied like scalar values.

Example :

$a = imagecreatetruecolor(10,10);
$b = $a;

var_dump($a, $b);

// resource(2, gd)

// resource(2, gd)
  • 写回答

3条回答 默认 最新

  • doushaju4901 2012-09-26 16:53
    关注

    So, the solution found was in the comment, and this is an implementation of it in a Image management class :

    public function __clone() {
        $original = $this->_img;
        $copy = imagecreatetruecolor($this->_width, $this->_height);
    
        imagecopy($copy, $original, 0, 0, 0, 0, $this->_width, $this->_height);
    
        $this->_img = $copy;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Excel发现不可读取的内容
  • ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。