【327】Python 中 PIL 实现图像缩放
参考:Python用Pillow(PIL)进行简单的图像操作(模糊、边缘增强、锐利、平滑等)
参考:廖雪峰 - Pillow
实现代码如下:
from PIL import ImageGrab
img = Image.open('D:/tmp/4.jpg')
# 获取图像的大小
print(img.size)
# 获取图像 width
print(img.size[0])
# 获取图像 height
print(img.size[1]) img = img.resize((width, height),Image.ANTIALIAS)
实现批量修改图片的尺寸,可以自定义输入和输出文件以及缩放比例。
代码如下:
# coding=utf-8
# 批量修改图片尺寸
# imageResize(r"D:\tmp", r"D:\tmp\3", 0.7) from PIL import ImageGrab
import os def imageResize(input_path, output_path, scale):
# 获取输入文件夹中的所有文件/夹,并改变工作空间
files = os.listdir(input_path)
os.chdir(input_path)
# 判断输出文件夹是否存在,不存在则创建
if(not os.path.exists(output_path)):
os.makedirs(output_path)
for file in files:
# 判断是否为文件,文件夹不操作
if(os.path.isfile(file)):
img = Image.open(file)
width = int(img.size[0]*scale)
height = int(img.size[1]*scale)
img = img.resize((width, height), Image.ANTIALIAS)
img.save(os.path.join(output_path, "New_"+file)
【327】Python 中 PIL 实现图像缩放的更多相关文章
- 关于python中PIL的安装
python 的PIL安装是一件很蛋痛的事, 如果你要在python 中使用图型程序那怕只是将个图片从二进制流中存盘(例如使用Scrapy 爬网存图),那么都会使用到 PIL 这库,而这个库是出名的难 ...
- python中PIL模块
Image模块 Image模块是在Python PIL图像处理中常见的模块,对图像进行基础操作的功能基本都包含于此模块内.如open.save.conver.show-等功能. open类 Image ...
- 使用Python中PIL图形库进行截屏
目的:通过使用Python的一个图形库PIL(Python Image Library)对屏幕进行截图 步骤: 1.下载PIL(路径)并安装 2.新建文件“截屏.py”,右键Edit with IDL ...
- Python中PIL及Opencv转化
转载:http://blog.sina.com.cn/s/blog_80ce3a550102w26x.html Convert between Python tuple and list a = (1 ...
- python中PIL.Image和OpenCV图像格式相互转换
PIL.Image转换成OpenCV格式: import cv2 from PIL import Image import numpy image = Image.open("plane.j ...
- python 中PIL.Image和OpenCV图像格式相互转换
PIL.Image转换成OpenCV格式: import cv2 from PIL import Image import numpy image = Image.open("plane ...
- python中PIL库的使用
API参考 打开dos窗口,安装库: pip install pillow 很明显,图片有点大,咱们缩略一下: from PIL import Image im = Image.open(" ...
- 【美工设计 - Adobe Illustrator】基本设置 (图像显示 | 图像缩放 | 置入导出 | 标尺 | 网格 | 参考线 | 画板)
作者 : 韩曙亮 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/50232767 一. 基础操作 1. 设置图像显示效果 (1) ...
- opencv3 图像处理(一)图像缩放( python与c++ 实现)
opencv3 图像处理 之 图像缩放( python与c++实现 ) 一. 主要函数介绍 1) 图像大小变换 Resize () 原型: void Resize(const CvArr* src,C ...
随机推荐
- ActiveX开发
转自(http://blog.csdn.net/mingojiang/article/details/8159263) 一.ActiveX基础 1.1什么是ActiveX ActiveX是COM规范的 ...
- TWain 在 Qt4 中的调用方法
1.开发环境 Windows7_sp1_x64 Qt4.7.4 + mingw32 twain_32.dll (1.7.1.3) 2.常用缩写 DSM: Data Source Manager 数据源 ...
- CF 483B. Friends and Presents 数学 (二分) 难度:1
B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Android 遍历全国的地区二(获取天气)
根据上次的内容 1. 界面布局 weather_layout.xml <LinearLayout xmlns:android="http://schemas.android.com/a ...
- 一次SQLServer索引损坏问题的排查与修复
线上库执行一项数据变更操作时,一直提示"出现错误 8646.请记录该错误和时间,并与您的系统管理员联系." 通过代码排查,最终确定是在执行某存储过程时触发了如下错误,并指明了位置是 ...
- Rancher快速入门
https://www.cnrancher.com/docs/rancher/v2.x/cn/overview/quick-start-guide/
- Python3 字典Dict(十三)
Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度. 字典是另一种可变容器模型,且可存储任意类 ...
- STL标准库-容器-map和multimap
技术在于交流.沟通,本文为博主原创文章转载请注明出处并保持作品的完整性 map与multimap为关联容器,结构如下 map底层实现依然是rb_tree 他的data可以改,但是key不能改,因此ma ...
- L198
One of the most common birth defects throughout the world is a cleft lip. Babies born with a cleft l ...
- Win7系统Visual Studio 2013配置OpenCV3.1图文详解
Win7系统Visual Studio 2013配置OpenCV3.1图文详解 OpenCV3.1对硬件加速和移动开发的支持相对于老版本都有了较大改进,支持新的开发工具,更易于扩展,配置方式也比以前简 ...