'How to convert PPM image file to JPG or PNG using Python? [duplicate]

I have made a script which makes a valid ppm file which when opened using a ppm viewer is working properly.

But I don't want my users to install a ppm viewer to view their output images instead I want it to be converted to a global file format like a JPG/JPEG or PNG.



Solution 1:[1]

You can use Pillow module for python.

from PIL import Image
with Image.open("your_ppm_file.ppm") as im:
     im.save("your_jpg_file.jpg")

Hope this might be helpful.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1