【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 ...
随机推荐
- WebApi用Post的方式提交Json时,获取不到值或不进对应方法的问题
又是一个通宵,终于搞明白了. 被WebApi坑得好惨. 之前用各种方法Post上来,有时可以读到结构,但没值,有时直接就是一个Null,有时连方法都没进就跑了,只是来控制器里看了一下…… 最后好友说还 ...
- java生成doc和jar
生成doc帮助文档. 第一步,需要有一个java类,里面封装了各种方法 第二部,给类和方法添加注释文档 注释文档格式: /** * */ @author 作者 @version 版本 @return ...
- python多任务的导包问题
多线程的使用: import threading def func(x): print(x) t= threading.Thread(target=func,args=(12,)) # 线程启动 t. ...
- HDU3335 Divisibility Dilworth定理+最小路径覆盖
首先需要一些概念: 有向图,最小路径覆盖,最大独立集,Dilworth,偏序集,跳舞链(DLX).... 理解一: 对于DAG图,有:最大独立集=点-二分匹配数,二分匹配数=最小路径覆盖. 而无向图, ...
- spring-security-4 (5)spring security Java配置实现自定义表单认证与授权
前面三篇讲解了spring security的搭建以及简单的表单认证与授权原理.本篇将实现我们自定义的表单登录与认证. 本篇不会再讲项目的搭建过程,因为跟第二节的搭建如出一辙.本篇也不会将项目中所有 ...
- sql server 多行合并一行
1. 使用函数 go CREATE FUNCTION dbo.fn_Sumtype(@type varchar(50))RETURNS varchar(8000)ASBEGIN DECLARE @va ...
- [C++/Python] 如何在Python中使用一个DLL? (Windows环境)
开发环境VS2012, WIN7 64. 首先生成的DLL大致如下: .h文件 #ifdef CVINPYTHON_EXPORTS #define CVINPYTHON_API __declspec( ...
- 解决 eclipse tomcat cannot create a server using the selected type
解决的方法 1.退出eclipse: 2.打开 [工程目录下]/.metadata/.plugins/org.eclipse.core.runtime/.settings目录: 3.删除org.ecl ...
- 【linux】ls常用参数
1. 命令格式: ls [选项] [目录名] 2. 命令功能: 列出目标目录中所有的子目录和文件. 3. 常用参数: -a, –-all 列出目录下的所有文件,包括以 . 开头的隐含文件 -d, –- ...
- erlang的一些系统限制修改
atom个数限制 +t xxx 进程数限制 +P xxxx ets表个数限制 +e xxx ports个数限制 +Q xxxx 查看限制 string:tokens(binary_to_list(er ...