Python 图像处理库PIL ImageOps笔记

复制代码
# 返回一个指定大小的裁剪过的图像。该图像被裁剪到指定的宽高比和尺寸。
# 变量size是要求的输出尺寸,以像素为单位,是一个(宽,高)元组
# bleed:允许用户去掉图像的边界(图像四个边界)。这个值是一个百分比数(0.01表示百分之一)。默认值是0(没有边界),最高0.5
# centering: 用于控制裁剪位置。
#     (0.5,0.5) 是裁剪中心(如果裁剪宽度,裁掉左侧50%(右侧50%),顶/底一样)。
#     (0.0,0.0) 将从左上角开始裁剪(如果裁剪宽度,将从右边裁剪掉所要裁剪的部分;如果裁剪高度,将从底部裁剪掉所要裁剪的部分)。
#     (1.0,0.0) 将从左下角开始裁剪(如果裁剪宽度,将从左边裁剪掉所要裁剪的部分;如果裁剪高度,将从底部裁剪掉所要裁剪的部分)




def fit(image, size, method=Image.Resampling.BICUBIC, bleed=0.0, centering=(0.5, 0.5)):
python 复制代码
from PIL import Image, ImageOps


# 1280*720
im02 = Image.open("./sdout/2.png")

# 上左
im0 = ImageOps.fit(im02, (1000,500), Image.BICUBIC, 0.0, (0.0,0.0))
im0.save("./im0.png")
python 复制代码
from PIL import Image, ImageOps


# 1280*720
im02 = Image.open("./sdout/2.png")

# 下 右
im0 = ImageOps.fit(im02, (1000,500), Image.BICUBIC, 0.0, (1.0,1.0))
im0.save("./im0.png")
python 复制代码
from PIL import Image, ImageOps


# 1280*720
im02 = Image.open("./sdout/2.png")

# 上右
im3 = ImageOps.fit(im02, (1000,500), Image.BICUBIC, 0.0, (0.0,1.0))
im2.save("./im2.png")
python 复制代码
from PIL import Image, ImageOps


# 1280*720
im02 = Image.open("./sdout/2.png")

# 下左
im3 = ImageOps.fit(im02, (1000,500), Image.BICUBIC, 0.0, (1.0,0.0))
im2.save("./im2.png")

参考:

Python图像处理库PIL的ImageOps模块介绍 -----> 一些基本的图像操作_修炼打怪的小乌龟的博客-CSDN博客

PythonInformer - Image resizing recipes in Pillow

相关推荐
码界奇点21 小时前
Python从0到100一站式学习路线图与实战指南
开发语言·python·学习·青少年编程·贴图
智者知已应修善业21 小时前
【求中位数】2024-1-23
c语言·c++·经验分享·笔记·算法
张人玉1 天前
百度 AI 图像识别 WinForms 应用代码分析笔记
人工智能·笔记·百度
Laravel技术社区1 天前
pytesseract 中英文 识别图片文字
python
xqqxqxxq1 天前
背单词软件技术笔记(V1.0核心版及V2.0随机挖字母)
笔记
YJlio1 天前
Active Directory 工具学习笔记(10.8):AdInsight——保存与导出(证据留存、共享与二次分析)
数据库·笔记·学习
生骨大头菜1 天前
使用python实现相似图片搜索功能,并接入springcloud
开发语言·python·spring cloud·微服务
绝不收费—免费看不了了联系我1 天前
Fastapi的单进程响应问题 和 解决方法
开发语言·后端·python·fastapi
xqqxqxxq1 天前
背单词软件技术笔记(V2.0扩展版)
java·笔记·python
最晚的py1 天前
Python抓取ZLibrary元数据
爬虫·python