本文介绍了wand-py中是否有一个-level函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

wand-py中是否有-level函数来调整图像的水平?

Is there a -level function in wand-py to adjust the levels of an image?

如何访问此内容?

推荐答案

-level操作或 MagickLevelImage C-API,目前在wand-py中不存在.但是,wand.api使得添加对这种方法的支持非常容易.

The -level operation, or MagickLevelImage C-API, does not currently exists in wand-py. However, wand.api makes adding support for this method very easy.

扩展wand.image.Image类的示例:

from ctypes import c_void_p, c_double, c_int
from wand.api import library
from wand.image import Image

# Define C-API method signatures
library.MagickLevelImage.argtypes = [c_void_p,  # wand
                                     c_double,  # black_point
                                     c_double,  # gamma
                                     c_double]  # white_point
library.MagickLevelImage.restype = c_int


class MyImage(Image):
    def level(self, black, white, gamma=1.0):
        # Assert black, gamma, & white are float types
        # between 0.0 & 1.0.
        # Both black & white values must be converted to
        # QuantumRange percentages.
        quantum = float(self.quantum_range)
        return library.MagickLevelImage(self.wand,
                                        black * quantum,
                                        gamma,
                                        white * quantum)

if __name__ == '__main__':
    # convert rose: -level 20%,50% rose_level.png
    with MyImage(filename='rose:') as image:
        image.level(0.2, 0.5)
        image.save(filename='rose_level.png')

这篇关于wand-py中是否有一个-level函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 19:37