class_docstr: A datasource that lets you read images.
class_docstr_tok: ["A","datasource","that","lets","you","read","images","."]
code: def _read_stream(
      self,
      f: "pyarrow.NativeFile",
      path: str,
  ) -> Iterator[Block]:
      from PIL import Image, UnidentifiedImageError
  
      data = f.readall()
  
      try:
          image = Image.open(io.BytesIO(data))
      except UnidentifiedImageError as e:
          raise ValueError(
              f"PIL couldn't load image file at path '{path}'."
          ) from e
  
      if self.size is not None:
          height, width = self.size
          image = image.resize((width, height))
      if self.mode is not None:
          image = image.convert(self.mode)
  
      builder = DelegatingBlockBuilder()
      array = np.array(image)
      item = {"image": array}
      builder.add(item)
      block = builder.build()
  
      yield block
  
imports: import io
  import logging
  import time
  from typing import TYPE_CHECKING, Iterator, List, Optional, Tuple, Union
  import numpy
  from ray.data._internal.delegating_block_builder import DelegatingBlockBuilder
  from ray.data._internal.util import _check_import
  from ray.data.block import Block, BlockMetadata
  from ray.data.datasource.file_based_datasource import FileBasedDatasource
  from ray.data.datasource.file_meta_provider import DefaultFileMetadataProvider
  from ray.util.annotations import DeveloperAPI
label_desc: Use image node_id 2 for calling the ImageDatasource obj's underlying member method code with example usage: obj._read_stream(f, path) without return types