Python中的魔杖调整大小()函数
调整图像大小是指更改原始图像的尺寸,以便将原始图像转换为最适合使用的尺寸。 Scaling Down是指缩小图像的尺寸并使图像尺寸更小。而Scaling Up是指增加图像的尺寸,并使图像尺寸更大。
resize()函数用于调整图像大小。
Syntax:
Parameters :Parameter Input Type Description width numbers.Integral New width of image height numbers.Integral New height of image filter basestring or numbers.Integral A filter type to use for resizing. blur numbers.Real The blur factor where > 1 is blurry, < 1 is sharp
示例 1:
输入图像:
Python3
wand.image.resize(width=None, height=None, filter='undefined', blur=1)
Python3
# import Image from wand.image
from wand.image import Image
# read image using Image() function
with Image(filename = 'gog.png') as img:
# resize image using resize() function
img.resize(50, 50, filter = 'undefined, blur = 1)
# save resized image
img.save(filename = 'resized_gog.png')
输出 :
示例 2:
输入图像:
输入将来自一个 url。 GeeksforGeeks
Python3
# import required libraries
import urllib3
from cStringIO import StringIO
from wand.image import Image
from wand.display import display
# load image from url
http = urllib3.PoolManager()
r = http.request('GET', 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-6.png')
f = StringIO(r.data)
# read image using Image() function
with Image(file=f) as img:
# resize image using resize() function
img.resize(400, 300)
# save image
img.save(filename = 'gogurl.png')
# display final image
display(img)
输出 :