Create square thumbnails with Python + MagickWand
Question: How can I create square thumbnails with Python and Wand? I'm trying to make
square thumbnails from source images of any size. It's important that the
thumbnail have the same aspect ratio as the original, cropping is ok, and it
should fill the sapce of the thumbnail.


Answer: The following `crop_center()` function makes the given image square.

    
    
    from __future__ import division
    
    from wand.image import Image
    
    
    def crop_center(image):
        dst_landscape = 1 > image.width / image.height
        wh = image.width if dst_landscape else image.height
        image.crop(
            left=int((image.width - wh) / 2),
            top=int((image.height - wh) / 2),
            width=int(wh),
            height=int(wh)
        )
    

First you need to make the image square, and then you can
[`resize()`](http://docs.wand-
py.org/en/0.3.7/wand/image.html#wand.image.BaseImage.resize) the square
smaller.

