あなたの場合、setGravity
メソッドはオブジェクトに適用する必要があり$im
ます。しかし、とにかく、重力は で挿入された ImagickDraw オブジェクトにのみ影響するように見えます。ImageMagickdrawImage
コマンドでできるように、画像を描画に入れる方法はありません。
したがって、これを行うには 2 つの方法があります。
1位。ホスティングで関数shell_exec
またはが許可されている場合exec
は、次のようなコマンドを実行できます。
convert image.jpg -gravity south -\
draw "image Over 0,0 0,0 watermak.png" \
result.jpg`
2番目。それ以外の場合は、ベース画像に配置されている画像の位置を計算して使用できます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);