Pgmagick spread() 方法 – Python
spread()函数是 Pgmagick 库中的一个内置函数,用于以随机量置换图像像素。该函数在成功时返回真值。
Syntax:
spread(thresholdLevel)
Parameters: This function accept two parameters as mentioned above and described below:
Return Value: This function returns the Pgmagick object with image added.
Input Image:
Example 1:
from pgmagick import Image, DrawableCircle, DrawableText
from pgmagick import Geometry, Color
# draw the image of dimension 600 * 600
img = Image('input.png')
# invoke spread function with factor as 5
img.spread(5)
# invoke write function along with filename
img.write('2_a.png')
Output:
Example 2:
# import library
from pgmagick import Image, DrawableCircle, DrawableText
from pgmagick import Geometry, Color
# Draw image of dimension 600 * 600 having background green
im = Image(Geometry(600, 600), Color("# 32CD32"))
# invoke DrawableCircle() function
circle = DrawableCircle(100, 100, 300, 20)
# invoke draw() function
im.draw(circle)
# set font size to 40px
im.fontPointsize(40)
# invoke DrawableText() function
text = DrawableText(250, 450, "GeeksForGeeks")
# invoke draw() function
im.draw(text)
# invoke spread function with factor as 4
im.spread(4)
# invoke write function along with filename
im.write('1_b.png')
Output:
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。