class_docstr: A class that keeps all conversation history.
class_docstr_tok: ["A","class","that","keeps","all","conversation","history","."]
code: def get_images(self, return_pil=False):
      images = []
      for i, (role, msg) in enumerate(self.messages[self.offset :]):
          if i % 2 == 0:
              if type(msg) is tuple:
                  import base64
                  from io import BytesIO
                  from PIL import Image
  
                  msg, image, _, image_process_mode = msg
                  if image is None:
                      continue
                  if image_process_mode == "Pad":
  
                      def expand2square(
                          pil_img, background_color=(122, 116, 104)
                      ):
                          width, height = pil_img.size
                          if width == height:
                              return pil_img
                          elif width > height:
                              result = Image.new(
                                  pil_img.mode,
                                  (width, width),
                                  background_color,
                              )
                              result.paste(
                                  pil_img, (0, (width - height) // 2)
                              )
                              return result
                          else:
                              result = Image.new(
                                  pil_img.mode,
                                  (height, height),
                                  background_color,
                              )
                              result.paste(
                                  pil_img, ((height - width) // 2, 0)
                              )
                              return result
  
                      image = expand2square(image)
                  elif image_process_mode in ["Default", "Crop"]:
                      pass
                  elif image_process_mode == "Resize":
                      image = image.resize((336, 336))
                  else:
                      raise ValueError(
                          f"Invalid image_process_mode: {image_process_mode}"
                      )
                  max_hw, min_hw = max(image.size), min(image.size)
                  aspect_ratio = max_hw / min_hw
                  max_len, min_len = 800, 400
                  shortest_edge = int(
                      min(max_len / aspect_ratio, min_len, min_hw)
                  )
                  longest_edge = int(shortest_edge * aspect_ratio)
                  W, H = image.size
                  if longest_edge != max(image.size):
                      if H > W:
                          H, W = longest_edge, shortest_edge
                      else:
                          H, W = shortest_edge, longest_edge
                      image = image.resize((W, H))
                  if return_pil:
                      images.append(image)
                  else:
                      buffered = BytesIO()
                      image.save(buffered, format="PNG")
                      img_b64_str = base64.b64encode(
                          buffered.getvalue()
                      ).decode()
                      images.append(img_b64_str)
      return images
  
file_path: llama-vid/llamavid/conversation.py
imports: import dataclasses
  from enum import auto, Enum
  from typing import List, Tuple
label_desc: Use image node_id 4 for calling the Conversation obj's underlying member method code with example usage: obj.get_images(return_pil) and returns: images, pil_img, result, result