-1

How can I convert a PNG file to JPEG without Pillow on kivy (Python)?

Any help will be appreciated. Thank you!

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
i.r.b.a
  • 69
  • 3
  • 18
  • Possible duplicate of [Converting .jpg images to .png](https://stackoverflow.com/questions/10759117/converting-jpg-images-to-png) – theantomc Mar 14 '19 at 21:29

1 Answers1

2

Use Kivy CoreImage to convert from png to jpg.

Snippets

from kivy.core.image import Image as CoreImage

img = CoreImage("linux.png")
img.save("linux.jpg")

Example

main.py

from kivy.uix.screenmanager import Screen
from kivy.core.image import Image as CoreImage
from kivy.lang import Builder
from kivy.base import runTouchApp

Builder.load_string('''
#:kivy 1.10.1

<Demo>:
    img_png: img_png
    img_jpg: img_jpg

    RelativeLayout:
        Image:
            id: img_png
            pos_hint: {"left": 1, 'bottom': 1}
            size_hint: 0.5, 1
            allow_stretch: True

    RelativeLayout:
        Image:
            id: img_jpg
            pos_hint: {"right": 1, 'bottom': 1}
            size_hint: 0.5, 1
            allow_stretch: True
''')


class Demo(Screen):

    def __init__(self, **kwargs):
        super(Demo, self).__init__(**kwargs)
        img = CoreImage("linux.png")
        img.save("linux.jpeg")
        self.img_png.source = "linux.png"
        self.img_jpg.source = "linux.jpeg"


runTouchApp(Demo())

Output

Converted image from png and jpeg

ikolim
  • 15,721
  • 2
  • 19
  • 29