[英]Python Wand vs imagemagick brightness-contrast command
幸運的是, -brightness-contrast
只是調用在wand中實現的-function Polynomial
方法。 需要一些非常簡單的數學運算將brightness x contrast
參數轉換為slop x intercept
。
import math
from wand.image import Image
class MyImage(Image):
def brightness_contrast(self, brightness=0.0, contrast=0.0):
slope=math.tan((math.pi * (contrast/100.0+1.0)/4.0))
if slope < 0.0:
slope=0.0
intercept=brightness/100.0+((100-brightness)/200.0)*(1.0-slope)
self.function("polynomial", [slope, intercept])
with MyImage(filename="rose:") as img:
img.brightness_contrast(0.0, 10.0)
img.save(filename="rose.png")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.