Python实现图像尺寸和格式转换处理的示例详解

这篇文章主要为大家详细介绍了如何利用Python实现图像尺寸获取和格式转换处理的功能,文中的示例代码讲解详细,感兴趣的可以了解一下

实现代码

# batch_handle_image.py import argparse import glob import os from PIL import Image def main(args): limit_shortest = int(args.limitshortest) shortest_edge = int(args.shortestedge) longest_edge = int(args.longestedge) limit_width_or_height = int(args.limitwidthorheight) limit_width = int(args.limitwidth) limit_height = int(args.limitheight) to_webp = int(args.towebp) path_list = sorted(glob.glob(os.path.join(args.input, '*'))) for path in path_list: print(path) basename = os.path.splitext(os.path.basename(path))[0] img = Image.open(path) width, height = img.size # 限制最长边或最短边 if limit_shortest == 1: # save the smallest image which the shortest edge is shortest_edge if width 

使用命令

# 限最长边 2000px,并将格式转换为 webp 格式 python batch_handle_image.py --input /input_image --output /output_image --limitshortest 0 --longestedge 2000 --towebp 1 

到此这篇关于Python实现图像尺寸和格式转换处理的示例详解的文章就介绍到这了,更多相关Python图像内容请搜索0133技术站以前的文章或继续浏览下面的相关文章希望大家以后多多支持0133技术站!

以上就是Python实现图像尺寸和格式转换处理的示例详解的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » python