Effect picture:![](https://img-blog.csdnimg.cn/e8c833879a754075822e09a5dbf3f245.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAYmFieWFpOTk2,size_20,color_FFFFFF,t_70,g_se,x_16)
Implementation code:
import os
import easygui as a
import PIL.Image as Image
def resize_by_width(infile, image_size):
"""按照宽度进行所需比例缩放"""
im = Image.open(infile)
(x, y) = im.size
lv = round(x / image_size, 2) + 0.01
x_s = int(x // lv)
y_s = int(y // lv)
print("x_s", x_s, y_s)
out = im.resize((x_s, y_s), Image.ANTIALIAS)
return out
def get_new_img_xy(infile, image_size):
"""返回一个图片的宽、高像素"""
im = Image.open(infile)
(x, y) = im.size
lv = round(x / image_size, 2) + 0.01
x_s = x // lv
y_s = y // lv
# print("x_s", x_s, y_s)