0

I have a PNG image.

I can convert it to PBM using Pillow:

from PIL import Image

im = Image.open("myfig.png")
im.save("myfig.pbm")

However it seems that encoding P6 is used as default (https://en.wikipedia.org/wiki/Netpbm_format)

I would like to have P4 encoding. How can I do that with Pillow?

M.E.
  • 4,955
  • 4
  • 49
  • 128

1 Answers1

1

If you want P4, you need a single bit, binary image:

im = Image.open("myfig.png").convert('1')
im.save("myfig.pbm")
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432