参考:Python 中使用PIL中的resize 进行缩放

参考: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 实现图像缩放的更多相关文章

  1. 关于python中PIL的安装

    python 的PIL安装是一件很蛋痛的事, 如果你要在python 中使用图型程序那怕只是将个图片从二进制流中存盘(例如使用Scrapy 爬网存图),那么都会使用到 PIL 这库,而这个库是出名的难 ...

  2. python中PIL模块

    Image模块 Image模块是在Python PIL图像处理中常见的模块,对图像进行基础操作的功能基本都包含于此模块内.如open.save.conver.show-等功能. open类 Image ...

  3. 使用Python中PIL图形库进行截屏

    目的:通过使用Python的一个图形库PIL(Python Image Library)对屏幕进行截图 步骤: 1.下载PIL(路径)并安装 2.新建文件“截屏.py”,右键Edit with IDL ...

  4. Python中PIL及Opencv转化

    转载:http://blog.sina.com.cn/s/blog_80ce3a550102w26x.html Convert between Python tuple and list a = (1 ...

  5. python中PIL.Image和OpenCV图像格式相互转换

    PIL.Image转换成OpenCV格式: import cv2 from PIL import Image import numpy image = Image.open("plane.j ...

  6. python 中PIL.Image和OpenCV图像格式相互转换

    PIL.Image转换成OpenCV格式: import cv2 from PIL import Image import numpy   image = Image.open("plane ...

  7. python中PIL库的使用

    API参考 打开dos窗口,安装库: pip install pillow 很明显,图片有点大,咱们缩略一下: from PIL import Image im = Image.open(" ...

  8. 【美工设计 - Adobe Illustrator】基本设置 (图像显示 | 图像缩放 | 置入导出 | 标尺 | 网格 | 参考线 | 画板)

    作者 : 韩曙亮 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/50232767 一. 基础操作 1. 设置图像显示效果 (1) ...

  9. opencv3 图像处理(一)图像缩放( python与c++ 实现)

    opencv3 图像处理 之 图像缩放( python与c++实现 ) 一. 主要函数介绍 1) 图像大小变换 Resize () 原型: void Resize(const CvArr* src,C ...

随机推荐

  1. TextView上下滑动

    LocationResult = (TextView) findViewById(R.id.textView1);LocationResult.setMovementMethod(ScrollingM ...

  2. .ashx接口单元测试

    最近项目中需要修改一个文件上传的.ashx处理,代码的大概形式是这样的: public void ProcessRequest(HttpContext context) { CallA(context ...

  3. 宏使用 Tricks

    人为地定义一些"无意义"的宏(宏名本身有意义),以起到提升代码程序的可读性. 1. IN/OUT 指定参数用于输入还是输出: #define IN #define OUT void ...

  4. ElasticSearch(一):windows下安装ElasticSearch6.3.2

    前言 最近开始学习ElasticSearch,从官网上下载的最新版的es,但是网上安装教程大部分是早期5.X版本的,因为6.x版本出现了不同,所以记录下. 正文 1. 下载ElasticSearch ...

  5. TCP滑动窗口与回退N针协议

    [转]TCP 滑动窗口协议/1比特滑动窗口协议/后退n协议/选择重传协议 2014-1-5阅读884 评论0 本文转自 http://www.cnblogs.com/ulihj/archive/201 ...

  6. APScheduler - Advanced Python Scheduler

    简介 APScheduler:强大的任务调度工具,可以完成定时任务,周期任务等,它是跨平台的,用于取代Linux下的cron daemon或者Windows下的task scheduler. 内置三种 ...

  7. Cannot find name 'AsyncIterator' error in Typescript compilation process 问题解决

    解决方法: tsconfig.json: 添加lib 编译选项 { "compilerOptions": { "lib":[ "esnext.asyn ...

  8. 打造html右键菜单

    今天是给大家介绍一款在网页上使用的右键菜单,原作者的网址是:http://51jsr.javaeye.com/blog/305517 这个右键菜单已经非常优秀,不过呢.却是IE Only,而且在DTD ...

  9. windows内存debug技巧

    A) c++ memory/heap corrupt debug 技巧 1. catch first exception2. data breakpointVC tell us some addres ...

  10. 4.Appium实现自动化安装apk

    一.代码如下所示: from appium import webdriver import os apk_path = os.path.abspath(os.path.join(os.path.dir ...