魔杖的另一個模塊是wand.drawing。該模塊為我們提供了一些非常基本的繪圖函數。 wand.drawing.Drawing對象緩衝用於將形狀繪製為圖像的指令,然後可以將這些形狀繪製為零個或多個圖像。
用法: with Drawing() as draw:
Note:In the above syntax “as draw” is just a nomenclature and can be any string as needed. The Drawing function in Python wand take has no parameter.
範例1:
# Import important objects from wand library
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
# Create draw object using Drawing() function
with Drawing() as draw:
with Image(width = 200,
height = 200,
background = Color('green')) as img:
draw(img)
img.save(filename ='empty.gif')
輸出圖像:
畫一條線
範例2:
# Import important objects from wand library
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
# Create draw object using Drawing() function
with Drawing() as draw:
draw.stroke_color = Color('black')
draw.stroke_width = 2
draw.line((5, 5), (45, 50))
with Image(width = 200,
height = 200,
background = Color('green')) as img:
draw.draw(img)
img.save(filename ='line.gif')
輸出圖像:
相關用法
- Python Wand function()用法及代碼示例
- Python Wand gaussian_blur()用法及代碼示例
- Python Wand transform()用法及代碼示例
- Python Wand crop()用法及代碼示例
- Python Wand rotational_blur()用法及代碼示例
注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 Wand Drawing() function in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。