[Python] Unable to convert an image from PNG TO JPG using PIL (Python Image Library)

Discussão em 'Python' iniciado por Stack, Julho 26, 2025.

  1. Stack

    Stack Membro Participativo

    I use weasyprint library in python to convert an HTML template to png. Then I am trying to convert the png image to jpg using a python library named PIL(PILLOW).

    The PNG IMAGE is given below. [​IMG]

    But the image obtained after conversion using PIL is not what I was expecting. The colors are lost and only some components of the image are visible.

    from PIL import Image
    img = Image.open(file_path)
    rgb_im = img.convert('RGB')

    jpg_img_path = os.path.splitext(file_path)[0]
    jpg_img_path += '.jpg'
    rgb_im.save(jpg_img_path)


    When I tried to use an online editor, they have provided me the perfect image from the png. Below is the jpg image obtained from the online converter. [​IMG]

    And the Image when I have used PIL. [​IMG]

    Continue reading...

Compartilhe esta Página