【问题标题】:image watermark doesn't work图片水印不起作用
【发布时间】:2013-10-30 10:54:23
【问题描述】:

我正在尝试为上传的图片添加水印。 不幸的是,我收到了这个错误:'

警告: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);
?>

【问题讨论】:

  • 检查您的 logo.png 位置,它存储的位置。它应该在文件所在的同一目录中。

标签: php image watermark


【解决方案1】:

您也许可以使用我创建的textPainter 类在图像上打印文本: https://github.com/alvarotrigo/PHP-Backend/tree/master/textPainter

Living demo

【讨论】:

    【解决方案2】:

    我觉得你传递了错误的图像路径 $im = imagecreatefromjpeg($image); 。检查 $image 的值并出于测试目的将两个图像复制到同一目录并运行脚本。

    【讨论】:

      猜你喜欢
      • 2015-12-09
      • 1970-01-01
      • 1970-01-01
      • 2016-10-07
      • 1970-01-01
      • 2012-03-15
      • 1970-01-01
      • 2014-03-13
      • 2013-01-25
      相关资源
      最近更新 更多