【问题标题】:Is there a -level function in wand-pywand-py中是否有-level函数
【发布时间】:2015-04-09 00:15:00
【问题描述】:

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

我如何访问它?

【问题讨论】:

    标签: imagemagick wand


    【解决方案1】:

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

    扩展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')
    

    【讨论】:

    猜你喜欢
    • 2016-12-03
    • 2019-06-20
    • 1970-01-01
    • 1970-01-01
    • 2014-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多