def rescale_image(image: wx.Image, max_width: int, max_height: int): """ Rescale a wx.Image and return a wx.Bitmap. """ width, height = image.GetSize() ratio = width / height new_width = int(ratio * max_height) new_height = int(max_width / ratio) if new_width <= max_width: image.Rescale(new_width, max_height, wx.IMAGE_QUALITY_HIGH) else: image.Rescale(max_width, new_height, wx.IMAGE_QUALITY_HIGH) return wx.Bitmap(image)
def resizeImageToFit(image: wx.Image, max_width, max_height): r_w = max_width * 1.0 / image.GetWidth() r_h = max_height * 1.0 / image.GetHeight() r = min(r_w, r_h) new_width = image.GetWidth() * r new_height = image.GetHeight() * r image.Rescale(new_width, new_height)