code: def resize_image(
      cls,
      img_bytes: bytes,
      output: str = "png",
      thumb_size: WindowSize | None = None,
      crop: bool = True,
  ) -> bytes:
      thumb_size = thumb_size or cls.thumb_size
      img = Image.open(BytesIO(img_bytes))
      logger.debug("Selenium image size: %s", str(img.size))
      if crop and img.size[1] != cls.window_size[1]:
          desired_ratio = float(cls.window_size[1]) / cls.window_size[0]
          desired_width = int(img.size[0] * desired_ratio)
          logger.debug(
              "Cropping to: %s*%s", str(img.size[0]), str(desired_width)
          )
          img = img.crop((0, 0, img.size[0], desired_width))
      logger.debug("Resizing to %s", str(thumb_size))
      img = img.resize(thumb_size, Image.Resampling.LANCZOS)
      new_img = BytesIO()
      if output != "png":
          img = img.convert("RGB")
      img.save(new_img, output)
      new_img.seek(0)
      return new_img.read()
  
imports: from __future__ import annotations
  import logging
  from io import BytesIO
  from typing import TYPE_CHECKING
  from flask import current_app
  from superset import feature_flag_manager
  from superset.utils.hashing import md5_sha_from_dict
  from superset.utils.urls import modify_url_query
  from superset.utils.webdriver import ChartStandaloneMode, DashboardStandaloneMode, WebDriver, WebDriverPlaywright, WebDriverSelenium, WindowSize
label_desc: Use image node_id 9 for calling the BaseScreenshot obj's underlying member method code with example usage: obj.resize_image(cls, img_bytes, output, thumb_size, crop) and returns: new_img