【发布时间】:2016-02-14 15:18:53
【问题描述】:
我正在使用此代码将 png 图像作为水印添加到上传的图像,但结果不是图像并且不想使用 header() 我希望代码继续执行其他 php 查询而无需导航到另一个页面来显示图像。图片已上传但没有水印,并且 header() 不会发布任何图片,只是一个灰色的小方块
$path = "../large/";
$num = substr(md5(mt_rand(1,9999999999)),0,9);
$new_name = $path.$num.".jpg";
$image = $num.".jpg";
move_uploaded_file($img_tmpname,$new_name);
$image = imagecreatefromjpeg($new_name);
$logoImage = imagecreatefrompng("images/watermark.png");
imagealphablending($logoImage, true);
$imageWidth=imagesx($image);
$imageHeight=imagesy($image);
$logoWidth=imagesx($logoImage);
$logoHeight=imagesy($logoImage);
imagecopy(
// destination
$image,
// source
$logoImage,
// destination x and y
$imageWidth-$logoWidth, $imageHeight-$logoHeight,
// source x and y
0, 0,
// width and height of the area of the source to copy
$logoWidth, $logoHeight);
// Set type of image and send the output
header("Content-type: image/png");
imagePng($image);
// Release memory
imageDestroy($image);
imageDestroy($imageLogo);
【问题讨论】:
-
imagePng应该是imagepng和imageDestroy应该是imagedestroy -
路径
images/watermark.png~首先该文件是否存在于该位置,其次您是否尝试使用该图像的完整路径? -
是的,但我遇到了同样的问题
-
用这个作为最酷的例子。 stackoverflow.com/questions/8829674/…
标签: php image upload watermark