0

I would like to draw an image into another image with Wand (an ImageMagick binding for Python). The source image should totally replace the destination image (at given position).

I can use:

destinationImage.composite_channel(channel='all_channels', image=sourceImage, operator='replace', left=leftPosition, top=topPosition)

But I was wondering if there is a simple or faster solution.

arthur.sw
  • 11,052
  • 9
  • 47
  • 104

1 Answers1

3

But I was wondering if there is a simple or faster solution.

Not really. In the scope of , this would be one of the fastest methods. For simplicity, your already doing everything on one line of code. Perhaps you can reduce this with Image.composite.

destinationImage.composite(sourceImage, leftPosition, topPosition)

But your now compromising the readability of your current solution. Having the full command with channel='all_channels' & operator='replace' kwargs will help you in the long run. Think about revisiting the code in a year.

destinationImage.composite(sourceImage, leftPosition, topPosition)
# versus
destinationImage.composite_channel(channel='all_channels',
                                   image=sourceImage,
                                   operator='replace',
                                   left=leftPosition,
                                   top=topPosition)

Right away, without hitting the API docs, you know the second option is replacing destination with a source image across all channels. Those facts are hidden, or assumed, in the first variation.

emcconville
  • 23,800
  • 4
  • 50
  • 66
  • Thanks! Tell me if I am wrong, but I understand that `composite()` and `composite_channel( channel='all_channels', operator='replace')` do not perform the same operation: in the first case the two images are mixed (the fully transparent parts of the first image does not change the destination image) whereas in the second case the destination image will be totally replaced by the source image (in the area of interest). – arthur.sw Jan 27 '15 at 14:46
  • @arthur.sw you are correct in that they perform different operations. They tie to separate C-API's and **composite** [defaults to 'over'](https://github.com/dahlia/wand/blob/master/wand/image.py#L1643) operation. However, without seeing the high-level of what you doing/expecting, I'm focusing on the act of one image on to another in my example. – emcconville Jan 27 '15 at 15:09