简体   繁体   中英

How to motion blur with ImageMagick using wand?

I want to use motion blur with ImageMagick. Motion blur in ImageMagick documentation.

But in Wand there is only gaussian_blur. Gaussian blur in Wand documentation.

Is motion blur missing in wand?

Is motion blur missing in wand?

Yes, as of 0.4.3 there is no wand.image.Image.motion_blur method implemented on library.

You'll need to extend wand's API to include MagickMotionBlurImage .

import ctypes
from wand.image import Image
from wand.api import library

# Tell Python about the C method
library.MagickMotionBlurImage.argtypes = (ctypes.c_void_p,  # wand
                                          ctypes.c_double,  # radius
                                          ctypes.c_double,  # sigma
                                          ctypes.c_double)  # angle

# Extend wand.image.Image class to include method signature (remember error handling)
class MyImage(Image):
    def motion_blur(self, radius=0.0, sigma=0.0, angle=0.0):
        library.MagickMotionBlurImage(self.wand,
                                      radius,
                                      sigma,
                                      angle)


# Example usage
with MyImage(filename='rose:') as img:
    img.motion_blur(radius=8.0, sigma=4.0, angle=-57.0)
    img.save(filename='rose_motion.png')

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM