2014-08-30 93 views
-4

我有PHP上傳腳本,我需要在用戶上傳後在圖像上添加水印。爲圖像添加水印並將其保存爲圖像不是php文件

我嘗試過很多方法,但都在最後給你的PHP路徑預覽圖像

我需要做同樣在這個環節http://php.net/manual/en/image.examples-watermark.php但保存到實像這有這樣的「my_new_image_with_watermark映像路徑。 JPG」 不僅僅是file.php

代碼居然是:

<?php 
// Load the stamp and the photo to apply the watermark to 
$stamp = imagecreatefrompng('stamp.png'); 
$im = imagecreatefromjpeg('photo.jpeg'); 

// 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); 
?> 

感謝

+0

https://github.com/Sybio/ImageWorkshop – 2014-08-30 00:38:22

回答

1

取而代之的是:

// Output and free memory 
header('Content-type: image/png'); 
imagepng($im); 
imagedestroy($im); 

寫:

$filename = '/foo/bar.png'; 
imagepng($im, $filename); 
imagedestroy($im);