简体   繁体   中英

How to save a Pymaging PNG image?

I'm trying to test out the new pure-python imaging library called Pymaging .

Although it seems to be really well documented, I can't find any examples at all. I got as far as creating a new image with a background color, but when I try to save the blank image to a png image it says it doesn't support the format:

Traceback (most recent call last):
  File "C:\Users\BIGKIMO\Desktop\pymagingtest.py", line 6, in <module>
    img.save_to_path(r"C:\Users\BIGKIMO\Desktop\pymagingtest.png")
  File "C:\Users\BIGKIMO\Desktop\vshapes\thirdparty\pymaging\image.py", line 105, in save_to_path
    self.save(fobj, format)
  File "C:\Users\BIGKIMO\Desktop\vshapes\thirdparty\pymaging\image.py", line 98, in save
    raise FormatNotSupported(format)
FormatNotSupported: png

This is odd, because the docs say that PNG images are supported, and I even have the pymaging_png module (this is also not clear from the docs, not sure if one has to get those image format modules for each image format one wants to deal with?). I also thought it might be the distribute module dependency but I also installed that and still getting same error.

If it matters, I haven't actually installed the Pymaging module, but that shouldn't be strictly necessary since it is pure python, I just append its folder to the sys.path and import from there. Oh and I'm using Python 2.7 on a Windows 7 operating system.

My code is below:

import sys
sys.path.append(r"C:\Users\BIGKIMO\Desktop\vshapes\thirdparty")
import pymaging

img = pymaging.image.Image.new(pymaging.colors.RGBA, 1000,500, pymaging.colors.Color(22,22,222,0))
img.save_to_path(r"C:\Users\BIGKIMO\Desktop\pymagingtest.png")

Creator of Pymaging here. Thank you for your interest in this package.

Unfortunately, Pymaging is still very much in an experimental stage, and not at all ready for production. This is also why it has a distinct lack of end-user documentation. I'm a strong proponent of documenting code, so by not documenting this package, I want to indicate that it's not ready. This is why there's a lot more documentation about the internals, to make it easier for others to hack on this project.

Having said that, the PNG module should actually work. However your issue is most likely due to the fact that you don't have pymaging-png [1] installed. The main Pymaging package does not actually provide any format support by design, de-coupling the format release cycle and development from the main package. This means that just installing Pymaging will have the arguably unexpected result of not having a working install at all.

[1] https://github.com/ojii/pymaging-png

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM