                       self.image_id, (image.width(), image.height()), (self.width, self.height),
                       center_image)
          self._image = image
          self.itemconfig(self.image_id, image=self._image)
          self.config(width=self._image.width(), height=self._image.height())
          self.update_idletasks()
          if center_image:
              self._center_image(self.width / 2, self.height / 2)
          self.configure(scrollregion=self.bbox("all"))
          logger.debug("set canvas image. Canvas size: %s", (self.width, self.height))
 
</s> remove         logger.debug("Resizing image: (name: '%s', frame_dims: %s", name, frame_dims)
        displayimg = cast(Image.Image, self._previewtrain[name][0])
        if frame_dims:
            frameratio = float(frame_dims[0]) / float(frame_dims[1])
            imgratio = float(displayimg.size[0]) / float(displayimg.size[1])

            if frameratio <= imgratio:
                scale = frame_dims[0] / float(displayimg.size[0])
                size = (frame_dims[0], int(displayimg.size[1] * scale))
            else:
                scale = frame_dims[1] / float(displayimg.size[1])
                size = (int(displayimg.size[0] * scale), frame_dims[1])
            logger.debug("Scaling: (scale: %s, size: %s", scale, size)

            # Hacky fix to force a reload if it happens to find corrupted
            # data, probably due to reading the image whilst it is partially
            # saved. If it continues to fail, then eventually raise.
            for i in range(0, 1000):
                try:
                    displayimg = displayimg.resize(size, Image.ANTIALIAS)
                except OSError:
                    if i == 999:
                        raise
                    continue
                break
        self._previewtrain[name][1] = ImageTk.PhotoImage(displayimg)
 </s> add         logger.debug("Deleting previews")
        for item in os.listdir(self._pathpreview):
            if item.startswith(os.path.splitext(TRAININGPREVIEW)[0]) and item.endswith((".jpg",
                                                                                        ".png")):
                fullitem = os.path.join(self._pathpreview, item)
                logger.debug("Deleting: '%s'", fullitem)
                os.remove(fullitem)

        self._preview_extract.delete_previews()
        del self._preview_train
        del self._preview_extract
        self._preview_train = PreviewTrain(self._pathpreview)
        self._preview_extract = PreviewExtract(self._pathpreview) </s> remove         Parameters
        ----------
        name: str
            The name of the training image to be resized
        frame_dims: tuple, optional
            The (width (`int`), height (`int`)) of the display panel that will display the preview.
            ``None`` if the frame dimensions are not known.
 </s> add         Should be called when terminating tasks, or when Faceswap starts up or shuts down. </s> remove     def _pad_and_border(self, image: Image.Image, size: int) -> np.ndarray:
        """ Pad rectangle images to a square and draw borders

        Parameters
        ----------
        image: :class:`PIL.Image`
            The image to process
        size: int
            The size of the image as it should be displayed

        Returns
        -------
        :class:`PIL.Image`:
            The processed image
        """
        if image.size[0] != image.size[1]:
            # Pad to square
            new_img = Image.new("RGB", (size, size))
            new_img.paste(image, ((size - image.size[0]) // 2, (size - image.size[1]) // 2))
            image = new_img
        draw = ImageDraw.Draw(image)
        draw.rectangle(((0, 0), (size, size)), outline="#E5E5E5", width=1)
        retval = np.array(image)
        logger.trace("image shape: %s", retval.shape)  # type: ignore
        return retval

    def _process_samples(self,
                         samples: List[np.ndarray],
                         filenames: List[str],
                         num_images: int) -> bool:
        """ Process the latest sample images into a displayable image.
 </s> add     def _create_placeholder(self, thumbnail_size: int) -> None:
        """ Create a placeholder image for when there are fewer thumbnails available
        than columns to display them. </s> remove     def resize_image(self, name: str, frame_dims: Optional[Tuple[int, int]]) -> None:
        """ Resize the training preview image based on the passed in frame size.
 </s> add         """
        size = get_config().user_config_dict.get("icon_size", 16)
        size = int(round(size * get_config().scaling_factor))
        icons: Dict[str, ImageTk.PhotoImage] = {}
        pathicons = os.path.join(PATHCACHE, "icons")
        for fname in os.listdir(pathicons):
            name, ext = os.path.splitext(fname)
            if ext != ".png":
                continue
            img = Image.open(os.path.join(pathicons, fname))
            img = ImageTk.PhotoImage(img.resize((size, size), resample=Image.HAMMING))
            icons[name] = img
        logger.debug(icons)
        return icons
        if self._is_standalone:  # canvas size should not be updated inside GUI
            self.config(width=self._image.width(), height=self._image.height())

                       self.image_id, (image.width(), image.height()), (self.width, self.height),
                       center_image)
          self._image = image
          self.itemconfig(self.image_id, image=self._image)
        if self._is_standalone:  # canvas size should not be updated inside GUI
            self.config(width=self._image.width(), height=self._image.height())

          self.update_idletasks()
          if center_image:
              self._center_image(self.width / 2, self.height / 2)
          self.configure(scrollregion=self.bbox("all"))
          logger.debug("set canvas image. Canvas size: %s", (self.width, self.height))
keep keep keep keep replace keep keep keep keep keep
 GUI - Preview updates
  - Training preview. Embed preview pop-out window
  - Bugfix - convert/extract previews 
lib/training/preview_tk.py