在您的情况下setGravity
,方法应该应用于$im
对象。但无论如何,它看起来重力只影响 ImagickDraw 对象,插入drawImage
,并且没有办法像使用 ImageMagick 命令那样将图像放入绘图中。
所以有两种方法可以做到这一点:
第一个。如果您的主机允许功能shell_exec
或exec
,您可以运行类似的命令。
convert image.jpg -gravity south -\
draw "image Over 0,0 0,0 watermak.png" \
result.jpg`
第二。否则,您可以计算放置在基础图像上的图像的位置并使用compositeImage
$imageHight = $im->getImageHeight();
$imageWith = $im->getImageWidth();
// Scale the sprite if needed.
// Here I scale it to have a 1/2 of base image's width
$rating->scaleImage($imageWith / 2, 0);
$spriteWidth = $rating->getImageWidth();
$spriteHeight = $rating->getImageHeight();
// Calculate coordinates of top left corner of the sprite
// inside of the image
$left = ($imageWidth - $spriteWidth)/2; // do not bother to round() values, IM will do that for you
$top = $imageHeight - $spriteHeight;
// If you need bottom offset to be, say, 1/6 of base image height,
// then decrease $top by it. I recommend to avoid absolute values here
$top -= $imageHeight / 6;
$im->compositeImages($rating, imagick::COMPOSITE_OVER, $left, $top);