docs: def to_bytes(self, transparent=True, thumbnail_size=None, resampling=None, in_range='dtype', out_range='dtype',
                   format="png"):
          """
          Convert to selected format (discarding geo).
  
          Optionally also resizes.
          Note: for color images returns interlaced.
          :param transparent: if True - sets alpha channel for nodata pixels
          :param thumbnail_size: if not None - resize to thumbnail size, e.g. 512
          :param in_range: input intensity range
          :param out_range: output intensity range
          :param format : str, image format, default "png"
          :param resampling: one of Resampling enums
  
          :return bytes
          """
          resampling = resampling if resampling is not None else Resampling.cubic
  
          if self.num_bands < 3:
              warnings.warn("Deprecation: to_png of less then three bands raster will be not be supported in next \
  release, please use: .colorize('gray').to_png()", GeoRaster2Warning)
  
          if self.num_bands > 3:
              warnings.warn("Limiting %d bands raster to first three bands to generate png" % self.num_bands,
                            GeoRaster2Warning)
              three_first_bands = self.band_names[:3]
              raster = self.limit_to_bands(three_first_bands)
          elif self.num_bands == 2:
              warnings.warn("Limiting two bands raster to use the first band to generate png",
                            GeoRaster2Warning)
              first_band = self.band_names[:1]
              raster = self.limit_to_bands(first_band)
          else:
              raster = self
  
          if raster.image.dtype != np.uint8:
              warnings.warn("downscaling dtype to 'uint8' to convert to png",
                            GeoRaster2Warning)
              thumbnail = raster.astype(np.uint8, in_range=in_range, out_range=out_range)
          else:
              thumbnail = raster.copy_with()
  
          if thumbnail_size:
              if thumbnail.width > thumbnail.height:
                  thumbnail = thumbnail.resize(dest_width=thumbnail_size, resampling=resampling)
              else:
                  thumbnail = thumbnail.resize(dest_height=thumbnail_size, resampling=resampling)
  
          img, mask = thumbnail.to_pillow_image(return_mask=True)
  
          if transparent:
              mask = np.array(mask)[:, :, np.newaxis]
              mask = 255 - 255 * mask  # inverse
  
              if thumbnail.num_bands == 1:
                  img = np.stack([img, img, img], axis=2)  # make grayscale into rgb. bypass, as mode=LA isn't supported
  
              img = np.stack(tuple(np.split(np.asarray(img), 3, axis=2) + [mask]), axis=2)  # re-arrange into RGBA
              img = img[:, :, :, 0]
  
          f = io.BytesIO()
          imageio.imwrite(f, img, format)
          image_data = f.getvalue()
          return image_data