What are some effective strategies for finding a top-notch web development company in Zibo, China?

摘要:网站策划 英文,淄博比较好的网站建设公司,网页怎么做链接,wordpress4.4.1下载一、概述 1.1pillow简介 Python Imaging Library (PIL)是python 下的图像处理模块,支持多种格式&am
网站策划 英文,淄博比较好的网站建设公司,网页怎么做链接,wordpress4.4.1下载一、概述 1.1pillow简介 Python Imaging Library (PIL)是python 下的图像处理模块,支持多种格式#xff0c;并提供强大的图像处理功能#xff0c;可以通过pip进行安装后使用。 1.2pillow具体应用 Pillow 库是 Python3 最常用的图像处理库#xff0c;它支持多种图像格式并提供强大的图像处理功能可以通过pip进行安装后使用。 1.2pillow具体应用 Pillow 库是 Python3 最常用的图像处理库它支持多种图像格式可以用于图像处理、图像增强、图像合成等。下面是 Pillow 库中的一些常用函数open()打开一张图片new()创建一张新的图片save()保存一张图片show()显示一张图片resize()改变图片的大小crop()裁剪图片rotate()旋转图片transpose()翻转图片convert()转换图片的格式或色彩模式filter()使用滤镜处理图片getpixel()获取图片中指定位置的像素值putpixel()设置图片中指定位置的像素值paste()将一张图片粘贴到另一张图片上。 1.3快速入门 通过文件创建 Image 对象 通过文件创建 Image 图像对象是最常用的方法 示例通过文件创建 Image 图像对象 from PIL import Imageimage Image.open(D://桌面//1.jpeg) # 创建图像实例 # 查看图像实例的属性 print(image.format, image.size, image.mode)image.show() # 显示图像 格式转换并保存图像 pillow Image 模块中的 save 函数可以保存图片除非你指定文件格式否则文件的扩展名就是文件格式。 from PIL import Image import os# 打开图片 image_path D://桌面//1.png image Image.open(image_path)# 获取文件名与后缀 f, e os.path.splitext(image_path)# 指定输出文件格式 output_format jpeg # 要保存的文件格式比如 PNG、JPEG 等# 创建输出文件名 outfile f . output_format.lower()# 保存图片并指定文件格式 image.save(outfile, formatoutput_format)print(f图片已保存为 {outfile}格式为 {output_format}) image.show() save() 函数有两个参数如果文件名没有指定图片格式那么第二个参数是必须的他指定图片的格式。 二、课堂实操 2.1 创建缩略图 创建缩略图 使用 Image.thumbnail( size ), size 为缩略图宽长元组。 示例 创建缩略图 from PIL import Image import os# 打开图片 image_path D://桌面//1.png image Image.open(image_path)# 获取文件名与后缀 f, e os.path.splitext(image_path)# 指定输出文件格式 output_format PNG # 要保存的文件格式比如 PNG、JPEG 等# 创建输出文件名 outfile f _thumbnail. output_format.lower()# 创建缩略图 thumbnail_size (100, 100) # 缩略图尺寸 image.thumbnail(thumbnail_size)# 保存缩略图并指定文件格式 image.save(outfile, formatoutput_format)print(f缩略图已保存为 {outfile}格式为 {output_format})2.2剪贴粘贴、合并图像 2.2.1Image类包含允许您操作图像中的区域的方法。如要从图像中复制子矩形图像使用 crop() 方法。 2.2.2注意将子图region 粘贴paste回原图时粘贴位置 box 的像素与宽高必须吻合。而原图和子图的 mode 不需要匹配Pillow会自动处理。
阅读全文