复制图像变量GD库 [英] Duplicate a image variable GD library

查看:57
本文介绍了复制图像变量GD库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中复制图像变量的最简单方法是什么.

What is the easiest way to duplicate an image variable in PHP.

通常您可以简单地执行$varnew = $varold.

Normally you can simply do $varnew = $varold.

但是如果使用GD库变量,则执行上述操作,然后编辑$ varnew,然后$ varold也将生效.

But with a GD library variable if I did the above and then edited $varnew then $varold would be effected too.

显然,一种方法是重新打开文件或创建新图像并将其复制到其中.有没有更简单的方法?

Obviously one way would be to reopen the file or to make a new image and copy it into it. Is there an easier way?

推荐答案

尝试失败的原因是因为该变量仅存储GD映像的句柄(内存指针). $varnew$varold仍将存储相同的指针,从而指向内存中完全相同的图像.您必须使用图像复制,或者可能更糟的是,再次从文件中打开图像.

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.

这篇关于复制图像变量GD库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆