Reputation: 4956
Overview:
I got two images. The background image with 1920x1080p resolution and the overlay image that can be of any resolution less than 1920x1080p.
Background image(1920x1080):
Overlay image:(any size less <= 1920x1080)
Result image(1920x1080):
I am trying to overlay the overlay image exactly at the center of background image. I know how to do it using ImageMagick.
Solution using ImageMagick:
convert -composite -gravity center background.png overlay.png result.png
Expextation:
I am expecting to do the same using iMagick with the help of Imagick::compositeImage
and gravity center
. So please any one can help me out here.
Upvotes: 10
Views: 9866
Reputation: 24419
Imagick wraps the C-API MagickWand which doesn't automatically inherit the -composite -gravity
behavior. You will need to do the math yourself.
$background = new Imagick( __DIR__ . DIRECTORY_SEPARATOR . '6pEEG.png');
$window = new Imagick(__DIR__ . DIRECTORY_SEPARATOR . 'mpyY3.png');
$deltaX = $background->getImageWidth() - $window->getImageWidth();
$deltaY = $background->getImageHeight() - $window->getImageHeight();
$background->compositeImage($window,
Imagick::COMPOSITE_ATOP,
$deltaX / 2,
$deltaY / 2);
Upvotes: 7