I am trying to convert PNG images to PBM files. These PNG files are black and white and I need the resulting PBM to be a P1 bitmap which only contains 1s and 0s. So far the closest I have come is the following code:
img = Image.open("test part stl00000.png")
img = img.convert('1')
img.save("new.pbm")
However, this does not result in the desired output. When I open the output file in VS code, I get a bunch of question marks in diamond boxes along with red null boxes (it will not allow me to attach images here). When I open the file in notepad, it is blank spaces and y's with double dots above them. Does anyone know why my output is not 1s and 0s with the number of rows and columns corresponding to the size of the PNG I am converting?
Edit: I saw the post saying that I shouldn't expect to see the ASCII digits of 1s and 0s but that when I open it in a PBM viewer I would see the image I started with. This is correct, but unfortunately, I need the ASCII digits for the project I am working on. Does anyone know how I can do the conversion such that I end up with straight 1s and 0s so that I am able to manipulate it?