您好,我正在使用以下脚本,它运行良好。
我的问题是,如何用保留相同文件名和扩展名的带水印图像替换原始图像?
$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);
我试过了:
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