我需要在图像上添加水印。 我已经解决了使用此代码,运行良好,但图像位于左/下角。 如何在图像中心设置中心水印?
$img = 'test.jpg';
// Load the image where the logo will be embeded into
$image = imagecreatefromjpeg($img);
// Load the logo image
$logoImage = imagecreatefrompng("watermark.png");
imagealphablending($logoImage, true);
// Get dimensions
$imageWidth=imagesx($image);
$imageHeight=imagesy($image);
$logoWidth=imagesx($logoImage);
$logoHeight=imagesy($logoImage);
// Paste the logo
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);
答案 0 :(得分:5)
替换
// destination x and y
$imageWidth-$logoWidth, $imageHeight-$logoHeight,
与
// destination x and y
($imageWidth-$logoWidth)/2, ($imageHeight-$logoHeight)/2
,
答案 1 :(得分:0)
http://gloryplus.com/index.php?route=product/product&path=81&product_id=285
for($i=0; $i < $count; $i++)
{
("'".$im[$i]."'");
$imVar = imagecreatefromjpeg($im[$i]);
// First we create our stamp image manually from GD
$stamp = imagecreatefromgif('a.gif'); //imagecreatetruecolor(100, 54);
// 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);
// Merge the stamp onto our photo with an opacity (transparency) of 50%
imagecopymerge($imVar, $stamp, imagesx($imVar) - $sx - $marge_right, imagesy($imVar) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
// Save the image to file and free memory
imagepng($imVar, "./image/image[$i].png");
}