嗨,我使用下面的脚本,它完美的作品。PHP - 将水印图像保存到目录
我的问题是,我如何替换原来的图像与水印的留下相同的文件名和扩展名?
$stamp = imagecreatefrompng(base_static_url().$this->marker_url);
$im = imagecreatefromjpeg($img_path);
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
// Output and free memory
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
我tryed:
file_put_contents($img_path, imagecreatefromjpeg($im));
不过的了:
Error: failed to open stream: HTTP wrapper does not support writeable connections
而且我也试过:
file_put_contents($img_path, $im);
然后我得到了一个新的错误:
Error: file_put_contents(): supplied resource is not a valid stream resource
确定itryed imagejpeg(),因为原来的它是一个JPG要被替换。问题是http不允许取消链接,并且似乎传递给imagejpeg()的路径不正常,但可以加水印:/我收到:** imagejpeg()[function.imagejpeg]:无法打开'http:// localhost/site/uploads/img/iphone.jpg'写作:没有这样的文件或目录** – sbaaaang
你确定这是正确的网址吗?错误消息是说该路径不存在。你的php错误日志中是否有其他错误或警告? – Joe
嗯路径是绝对正确的:(我授予777访问只是为了测试:( – sbaaaang