4

Is it possible to convert a ppm file from p3 to p6 or use pillow lib to open and read a ppm p3 file?

I actually have ppm p3 files and trying to convert them to jpg using pillow lib, but unfortunately, it doesn't read p3 files only p6.

Any idea abou how can i get solve this?

from PIL import Image

im = Image.open("sweet_pic.ppm")
im.save("sweet_pic.jpg")

https://stackoverflow.com/a/26937263/8692977

Thanks.

Julien
  • 13,986
  • 5
  • 29
  • 53
Marsilinou Zaky
  • 1,038
  • 7
  • 17

1 Answers1

4

A P3 NetPBM file is ASCII (textual, and larger) whereas a P6 file is binary (and smaller). If you use ImageMagick the difference is made by specifying the compression:

# convert to P6 (binary)
convert image.ppm result.ppm

# convert to P3 (ASCII)
convert image.ppm -compress none result.ppm

The default, as usual, is to go to the smallest file type, i.e. P6, so you don’t need to do anything for that - as in first example above.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432