PPM to JPEG/JPG conversion for Python 3.4.1
Asked Answered
T

2

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.

Thiosinamine answered 14/11, 2014 at 19:7 Comment(0)
D
15

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.

Decry answered 14/11, 2014 at 19:15 Comment(3)
Documention says it supports 3.4, but not 3.4.1?Thiosinamine
@Thiosinamine 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.Decry
Didn't work because i had too many channels. I figured it out though using cv2 and PILCapful
R
2

You can use OpenCV

i = cv.imread('im0001.ppm')
cv.imwrite('im0001.jpg',i)
Recrystallize answered 27/1, 2020 at 18:54 Comment(2)
Tried that makes the image be very very bright. Any ideas?Capful
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 jpegCapful

© 2022 - 2024 — McMap. All rights reserved.