您现在的位置是:主页 > news > 昆山玉山网站建设/百度推广如何办理
昆山玉山网站建设/百度推广如何办理
admin2025/6/4 7:18:12【news】
简介昆山玉山网站建设,百度推广如何办理,工作室 网站建设,工作室名字Python图片缩放解释例子解释 Python 里对图片进行缩放可以使用 PIL.Image.resize 方法。 例子 对最大尺寸大于 1024 的图片进行缩放 from PIL import Image import shutildef main():input_path xxxoutput_path xxxfix_size 1024img Image.open(input_path)width img.…
昆山玉山网站建设,百度推广如何办理,工作室 网站建设,工作室名字Python图片缩放解释例子解释
Python 里对图片进行缩放可以使用 PIL.Image.resize 方法。
例子
对最大尺寸大于 1024 的图片进行缩放
from PIL import Image
import shutildef main():input_path xxxoutput_path xxxfix_size 1024img Image.open(input_path)width img.…
Python图片缩放
- 解释
- 例子
解释
Python 里对图片进行缩放可以使用 PIL.Image.resize 方法。
例子
对最大尺寸大于 1024 的图片进行缩放
from PIL import Image
import shutildef main():input_path = 'xxx'output_path = 'xxx'fix_size = 1024img = Image.open(input_path)width = img.widthheight = img.heightif width > height:if width > fix_size:img = Image.open(input_path)new_width = fix_sizenew_height = int(new_width * height / width)out = img.resize((new_width, new_height), Image.ANTIALIAS)out.save(output_path)else:shutil.copy(input_path, output_path)else:if height > fix_size:img = Image.open(input_path)new_height = fix_sizenew_width = int(new_height * width / height)out = img.resize((new_width, new_height), Image.ANTIALIAS)out.save(output_path)else:shutil.copy(input_path, output_path)if __name__ == '__main__':main()