嗨,我使用下面的腳本,它完美的作品。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