1

I'm using wand 0.4.1 and want to place an image on top another. The crux is that the image to be placed is lets say 400px wide but I want it to stretch to a different width, lets say 700px. The image should be stretched correctly with the aspect ratio staying the same.

I thought I could somehow do it with composite, but didn't know how to, since the only option I seem to be able to pass is top and left.

My current code is like this:

bg_image = open(bg_image_url, 'rb')
fg_image = open(fg_image_url, 'rb')
with Image(file=bg_image) as bg:
    with Image(file=fg_image) as fg:
        bg.composite(fg, left=100, top=100)
    bg.save(filename='composited_image.jpg')

How would I accomplish this with wand?

Hashirun
  • 89
  • 1
  • 9
  • ImageMagick offers a commandline option "-draw image over x,y w,h fg_image", where x and y are the location to place the top left corner on the background image and w,h are the dimensions to which you want the forerground image to be scaled. The first "image" in the option is just the word "image", not a filename. I assume there's some simple way to map that commandline option to a wand directive. – Glenn Randers-Pehrson Oct 18 '15 at 02:21
  • @GlennRanders-Pehrson Yes, I saw that option as well, but can't find a `wand` equivalent for the life of me... – Hashirun Oct 18 '15 at 10:22
  • Sorry but I don't know anything about wand. You could post a query on the ImageMagick Wand forum at http://www.imagemagick.org/discourse-server/viewforum.php?f=6 – Glenn Randers-Pehrson Oct 18 '15 at 12:20

1 Answers1

0

Wand's Transform is the method that I was looking for.

This can be used just right before the composite:

fg.transform(resize='300x') #resize 'fg' to a width of 300px 
                            #and height is set dynamically, 
                            #respecting the original aspect ratio
Hashirun
  • 89
  • 1
  • 9