7

Does anyone know of any way to convert a ppm file to a jpeg/jpg using python 3.4.1 specifically? I've looked around and can only find solutions for previous version of python.

star
  • 179
  • 1
  • 1
  • 6

2 Answers2

14

You can use the Pillow module. The following should work:

from PIL import Image

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

Read through the tutorial for more information.

MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • Documention says it supports 3.4, but not 3.4.1? – star Nov 14 '14 at 19:30
  • @star compatibility is by minor version (python versions are `major.minor.micro`, so 3.4.1 is minor version 3.4). So, if it says 3.4, it'll work with 3.4.0, 3.4.1, 3.4.2, etc. – MattDMo Nov 14 '14 at 19:33
  • Didn't work because i had too many channels. I figured it out though using cv2 and PIL – Xitcod13 Oct 01 '21 at 00:22
2

You can use OpenCV

i = cv.imread('im0001.ppm')
cv.imwrite('im0001.jpg',i)
Rupesh
  • 31
  • 1
  • Tried that makes the image be very very bright. Any ideas? – Xitcod13 Sep 08 '21 at 21:29
  • Alright i figured it out i converted the files to png with cv2 and then to jpg with Pillow `from PIL import Image im = Image.open("image_path") im.convert('RGB').save("image_name.jpg","JPEG") #this converts png image as jpeg` – Xitcod13 Oct 01 '21 at 00:18