#导入cv模块
import cv2 as cv2
#读取图像,支持 bmp、jpg、png、tiff 等常用格式
def size(jpg,now_size):
image = cv2.imread(jpg)
# 读取图像大小
size = image.shape
print('图像大小为', size)
# 创建窗口并显示图像,设定图像大小
if size[0]>now_size:
beishu=size[0]/now_size
res=cv2.resize(image,(now_size,int(size[1]/beishu)),interpolation=cv2.INTER_CUBIC)
#显示图像
# cv2.imshow('iker',res)
#保存图像
cv2.imwrite("./cat3.jpg", res, [int(cv2.IMWRITE_JPEG_QUALITY), 100])
# cv2.waitKey(0)
#释放窗口
# cv2.destroyAllWindows()
else:
print('图像不用缩小')
def main():
now_size = 500
jpg=r'./a.jpg'
size(jpg, now_size)
if __name__ == '__main__':
main()