簡體   English   中英

圖片水印不起作用

[英]image watermark doesn't work

我正在嘗試向上傳的圖像添加水印。 不幸的是,我收到此錯誤:

警告:imagecreatefromjpeg(upload / ##。jpg):無法打開流:在目錄中沒有這樣的文件或目錄

我正在使用php.net中的代碼進行一些更改:

  // Load the stamp and the photo to apply the watermark to
$stamp = imagecreatefrompng('logo.png');
$im = imagecreatefromjpeg($image);

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

您也許可以利用我創建的textPainter類在圖像上打印文本: https : //github.com/alvarotrigo/PHP-Backend/tree/master/textPainter

現場演示

我覺得您傳遞的圖片路徑錯誤$im = imagecreatefromjpeg($image); 檢查$ image的值,並出於測試目的將兩個圖像復制到同一目錄中並運行腳本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM