Search code examples
pythonpythonmagick

How to compose with center gravity in PythonMagick


I did appreciate the answer by Orbling on .composite():

flattened.composite(img, 0, 0, PythonMagick.CompositeOperator.SrcOverCompositeOp)

This is the form where the second image is placed to the (0, 0) coordinates of the original image. I tried, but I could not find how the image could be centered to the original.

The internal __doc__ says (formatted manually):

composite( (Image)arg1, 
           (Image)arg2, 
           (GravityType)arg3 
           [, (CompositeOperator)arg4]) -> None :

C++ signature :
    void composite(class Magick::Image {lvalue},
                   class Magick::Image,
                   enum MagickCore::GravityType 
                   [,enum MagickCore::CompositeOperator])

How should I enter the 3rd argument in Python code?


Solution

  • (You know, sometimes the answer is obvious when you formulate the question precisely.)

    The solution is:

    flattened.composite(img, 
                        PythonMagick.GravityType.CenterGravity,            # this
                        PythonMagick.CompositeOperator.SrcOverCompositeOp)