用于读取和写入paint.net(pdn)图像的python包。
pypdn的Python项目详细描述
简介
pypdn是一个用于读写paint.net(pdn)图像的python包。
“paint.net是用于运行windows的个人电脑的图像和照片编辑软件。它具有直观和创新的用户界面,支持图层、无限撤销、特殊效果和各种有用和强大的工具。一个活跃且不断发展的在线社区提供友好的帮助、教程和插件。“
使用paint.net时,保存图像的默认文件格式为pdn,这是paint.net使用的专有格式。与bmp、png、jpeg等格式相比,这种格式的优点在于它存储了传统图像格式中不存在的图层信息和属性。
你可以得到paint.net here。
paint.net是使用c(因此是.net)开发的。除了开头的一个基本XML头之外,它主要使用 C中的BinaryFormatter类,在保存图像时保存相关类。这使用NRBF protocol。开发了一个自定义读取器来读取nrbf文件和 然后这个库实际上只是将来自nrbf的数据解析为更可读和更友好的格式。你可以 从pypdn模块访问nrbf读取器,以防有任何用处。
安装
先决条件
- Python3
-
依赖关系:
- 努比
- SCIKIT图像
- AENUM
安装pypdn
pypdn当前在PyPi上可用。最简单的方法 单独安装在命令行使用pip:
pip install pypdn
安装最新版本。从存储库中安装最新的代码(通常是稳定的,但可能有 未记录的更改或错误):
pip install git+https://github.com/addisonElliott/pypdn.git
对于开发人员,可以克隆pypdn存储库并运行setup.py文件。使用以下命令获取 从github复制并安装所有依赖项:
git clone pip install git+https://github.com/addisonElliott/pypdn.git cd pypdn pip install .
或者,对于最后一行,请使用:
pip install -e .
要以“开发”或“可编辑”模式安装,可以对本地工作代码进行更改,python将使用 更新的代码。
测试和覆盖范围
要在任何平台上测试代码,请确保克隆github存储库以获取测试并从 存储库目录:
python -m unittest discover -v tests
示例
对于下面的示例,任何pdn文件都可以。如果您正在寻找一个示例,请查看tests/data目录 一些!
importpypdnimportmatplotlib.pyplotaspltlayeredImage=pypdn.read('Untitled3.pdn')print(layeredImage)# Contains width, height, version and layers of the image within the class# Version being the Paint.NET version that the image was saved with# Each layer contains the name, visibility boolean, opacity (0-255), isBackground and blendMode# From what I can tell, the isBackground property is not that useful# The blend mode is how the layer should be blended with the layers below it# These attributes are loaded from the PDN file but can be edited in the code as wellprint(layeredImage.layers)layer=layeredImage.layers[0]layer.visible=Truelayer.opacity=255layer.blendMode=pypdn.BlendType.Normallayer=layeredImage.layers[1]layer.visible=Truelayer.opacity=161layer.blendMode=pypdn.BlendType.Additive# Finally, the most useful thing is being able to combine the layers and flattn them into one image# Call the flatten function to do so# It will go through each layer and apply them IF the visibility is true!# The layer opacity and blend mode will be taken into effect## The flattened image is a RGBA Numpy array image# The asByte parameter determines the data type of the flattened image# If asByte is True, then the dtype will be uint8, otherwise it will be a float in range (0.0, 1.0)flatImage=layeredImage.flatten(asByte=True)plt.figure()plt.imshow(flatImage)# Individual layer images can be retrieved as well# Note: This does NOT apply blending or the layer opacity# Rather, it is the image data that is saved by Paint.NET for the layerplt.figure()plt.imshow(layeredImage.layers[1].image)plt.show()
使用tests/data目录中的untitled3.pdn,这是文本输出:
>>> print(layeredImage) pypdn.LayeredImage(width=800, height=600, version=System_Version(Major=4, Minor=21, Build=6589, Revision=7045), layers=[pypdn.Layer(name=Background, visible=True, isBackground=True, opacity=255, blendMode=<BlendType.Normal: 0>), pypdn.Layer(name=Layer 2, visible=True, isBackground=False, opacity=161, blendMode=<BlendType.Additive: 2>)]) >>> print(layeredImage.layers) [pypdn.Layer(name=Background, visible=True, isBackground=True, opacity=255, blendMode=<BlendType.Normal: 0>), pypdn.Layer(name=Layer 2, visible=True, isBackground=False, opacity=161, blendMode=<BlendType.Additive: 2>)]
路线图和错误
- 为nrbf和pdn类编写docstring并创建基本文档
- 修复nrbf reader中的id和classid混淆的问题
- 添加对写入nrbf文件的支持
- 为nrbf编写单元测试
- 添加对写入PDN文件的支持(必须先完成对NRBF文件的写入)
对于任何或所有问题,欢迎(并鼓励)拉取请求!
许可证
pypdn有一个基于mit的license。