pil扩展执行打开的jpeg图像的自动旋转

imdirect的Python项目详细描述


Build StatusCoverage Status

pil扩展执行打开的jpeg图像的自动旋转。

说明

拍摄对象或场景相对于 数码相机在所得图像的EXIF ^ {A3}数据中编码。 (假设它保存为JPEG格式)。当使用这种数码设备时 相机图像,此方向可能导致处理 形象,往往是很想被抵消的。

这个模块是Pillow的一个小扩展 monkey patchesPIL.Image.open方法 自动旋转图像[2](通过无损方法)并更新 相应地,如果图像是JPEG的,则将其标记为。

包还包含一个包含ExIF数据的保存方法 默认情况下保存JPEG时。

安装

pip install imdirect

用法

演示猴子修补程序及其工作原理:

>>>fromPILimportImage>>>importimdirect>>>img=Image.open('image.jpg')>>>print("{0}, Orientation: {1}".format(img,img._getexif().get(274)))<PIL.JpegImagePlugin.JpegImageFileimagemode=RGBsize=4032x3024at0x7F44B5E4FF10>,Orientation:6>>>imdirect.monkey_patch()>>>img_autorotated=Image.open('image.jpg')>>>print("{0}, Orientation: {1}".format(img_autorotated,img_autorotated._getexif().get(274)))<PIL.JpegImagePlugin.JpegImageFileimagemode=RGBsize=3024x4032at0x7F44B5DF5150>,Orientation:1

通过应用 imdirect.imdirect_open直接方法:

>>>fromimdirectimportimdirect_open>>>img=imdirect_open('image.jpg')

或者在PIL.Image.Image对象上使用imdirect.autorotate

>>>fromPILimportImage>>>importimdirect>>>img=Image.open('image.jpg')>>>img_rotated=imdirect.autorotate(img)

最后一个方法不返回PIL.JpegImagePlugin.JpegImageFile,但仍可以使用 如果原始图像的EXIF信息是不需要的。

测试

测试可以使用pytest

Testing started at 13:28 ...
=============================test session starts==============================
platform linux2 -- Python 2.7.12, pytest-3.0.1, py-1.4.31, pluggy-0.3.1
rootdir: /home/hbldh/Repos/imdirect, inifile:
collected 4 items

test_autorotate.py ...
test_monkey_patching.py .

===========================4 passed in 0.08 seconds===========================

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java组织。openqa。硒。遥远的UnreachableBrowserException如何定义EXE路径?   java Camel AdviceWith不使用指定文件替换端点   基于字符串的java图像加载   Java中的启发式算法,计算8个谜题状态的线性冲突   java为什么不支持文件。probeContentType返回null   JPA@EntityListeners、@PrePersist和Spring@RepositoryEventHandler、@HandleBeforeSave之间的java差异   可能前缀的Java字符串到字符串[]   安装rJava | Makefile时发生java错误。全部:38:target’libjri的配方。所以他失败了   Java公共静态void main()   java如何覆盖txt文件中的某些单词   java如何获得循环中生成的字符值之和?   java Log4j创建另一个具有相同属性的appender   java如何在从Axis2 Web服务客户端通过代理服务器调用Web服务时设置代理设置?   在Windows上安装Elasticsearch时发生java错误   java如何向EditText组件添加TextChangedListener?