def open_file(self):
        """
        Open image file for editing, scaling the smaller dimension and cropping the remainder.
        :return:
        """
        path, _ = QFileDialog.getOpenFileName(
            self,
            "Open file",
            "",
            "PNG image files (*.png); JPEG image files (*jpg); All files (*.*)",
        )

        if path:
            pixmap = QPixmap()
            pixmap.load(path)

            # We need to crop down to the size of our canvas. Get the size of the loaded image.
            iw = pixmap.width()
            ih = pixmap.height()

            # Get the size of the space we're filling.
            cw, ch = constants.CANVAS_DIMENSIONS

            if iw / cw < ih / ch:  # The height is relatively bigger than the width.
                pixmap = pixmap.scaledToWidth(cw)
                hoff = (pixmap.height() - ch) // 2
                pixmap = pixmap.copy(
                    QRect(
                        QPoint(0, hoff),
                        QPoint(cw, pixmap.height() - hoff),
                    )
                )

            elif iw / cw > ih / ch:  # The height is relatively bigger than the width.
                pixmap = pixmap.scaledToHeight(ch)
                woff = (pixmap.width() - cw) // 2
                pixmap = pixmap.copy(
                    QRect(
                        QPoint(woff, 0),
                        QPoint(pixmap.width() - woff, ch),
                    )
                )

            self.canvas.setPixmap(pixmap)

        Open image file for editing, scaling the smaller dimension and cropping the remainder.
        :return:
        
pyside2/demos/paint/main.py