FitImage#

Feature to automatically crop a Kivy image to fit your layout Write by Benedikt Zwölfer

Referene - https://gist.github.com/benni12er/95a45eb168fc33a4fcd2d545af692dad

Example:#

MDBoxLayout:
    size_hint_y: None
    height: "200dp"
    orientation: 'vertical'

    FitImage:
        size_hint_y: 3
        source: 'images/img1.jpg'

    FitImage:
        size_hint_y: 1
        source: 'images/img2.jpg'

Example with round corners:#

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/fitimage-round-corners.png
from kivy.uix.modalview import ModalView
from kivy.lang import Builder

from kivymd import images_path
from kivymd.app import MDApp
from kivymd.uix.card import MDCard

Builder.load_string(
    '''
<Card>:
    elevation: 10
    radius: [36, ]

    FitImage:
        id: bg_image
        source: "images/bg.png"
        size_hint_y: .35
        pos_hint: {"top": 1}
        radius: 36, 36, 0, 0
''')


class Card(MDCard):
    pass


class Example(MDApp):
    def build(self):
        modal = ModalView(
            size_hint=(0.4, 0.8),
            background=f"{images_path}/transparent.png",
            overlay_color=(0, 0, 0, 0),
        )
        modal.add_widget(Card())
        modal.open()


Example().run()

API - kivymd.uix.fitimage.fitimage#

class kivymd.uix.fitimage.fitimage.FitImage(**kwargs)#

Box layout class. See module documentation for more information.

source#

Filename/source of your image.

source is a StringProperty and defaults to None.

mipmap#

Indicate if you want OpenGL mipmapping to be applied to the texture. Read Mipmapping for more information.

New in version 1.0.0.

mipmap is a BooleanProperty and defaults to False.

reload(self)#