                  length = int(((len_x ** 2) + (len_y ** 2)) ** 0.5)
              sizes.append(length)
          logger.trace("sizes: '%s'", sizes)
          return sizes
  
      @staticmethod
      def save_face_with_hash(filename, extension, face):
          """ Save a face and return it's hash """
          f_hash, img = encode_image_with_hash(face, extension)
          logger.trace("Saving face: '%s'", filename)
          with open(filename, "wb") as out_file:
              out_file.write(img)
          return f_hash
 
</s> remove         cv2.imwrite(output_file, image)  # pylint: disable=no-member
 </s> add         if metadata:
            encoded_image = cv2.imencode(".png", image)[1]
            encoded_image = png_write_meta(encoded_image.tobytes(), metadata)
            with open(output_file, "wb") as out_file:
                out_file.write(encoded_image)
        else:
            cv2.imwrite(output_file, image)  # pylint: disable=no-member </s> remove         output_file = os.path.splitext(output_file)[0]+'.png'
 </s> add         output_file = os.path.splitext(output_file)[0] + ".png" </s> remove     def save_image(output_folder, filename, image):
 </s> add     def save_image(output_folder, filename, image, metadata=None): </s> remove     img = read_image(filename, raise_error=True)
    retval = sha1(img).hexdigest()
    if output_shape:
        retval = (retval, img.shape)
    logger.trace("filename: '%s', retval: %s", filename, retval)
 </s> add     retval = dict()
    if os.path.splitext(filename)[-1] != ".png":
        raise ValueError(f"Only png files are supported for reading exif data. ({filename})")
    with open(filename, "rb") as infile:
        chunk = infile.read(8)
        if chunk != b"\x89PNG\r\n\x1a\n":
            raise ValueError(f"Invalid header found in png: {filename}")
        while True:
            chunk = infile.read(8)
            length, field = struct.unpack(">I4s", chunk)
            logger.trace("Read chunk: (chunk: %s, length: %s, field: %s", chunk, length, field)
            if not chunk or field == b"IDAT":
                break
            if field == b"IHDR":
                # Get dimensions
                chunk = infile.read(8)
                retval["width"], retval["height"] = struct.unpack(">II", chunk)
                length -= 8
            elif field == b"iTXt":
                retval["itxt"] = eval(infile.read(length).split(b"\0\0\0\0\0", 1)[-1])
                break
            infile.seek(length + 4, 1)
    logger.trace("filename: %s, metadata: %s", filename, retval) </s> remove             output = "{}_{}{}".format(frame_name, str(idx), extension)
            if self._arguments.large:
                self._frames.save_image(self._faces_dir, output, face.aligned.face)
            else:
                output = os.path.join(self._faces_dir, output)
                f_hash = self._extracted_faces.save_face_with_hash(output,
                                                                   extension,
                                                                   face.aligned.face)
                if self._is_legacy:  # Generate the new thumbnail and store new face data for save
                    face.thumbnail = generate_thumbnail(face.aligned.face, size=96, quality=60)
                    self._alignments.data[filename]["faces"][idx] = face.to_alignment()
                self._alignments.data[filename]["faces"][idx]["hash"] = f_hash
 </s> add             output = "{}_{}.png".format(frame_name, str(idx))
            meta = dict(alignments=face.to_png_meta(),
                        source=dict(alignments_version=self._alignments.version,
                                    original_filename=output,
                                    face_index=idx,
                                    source_filename=filename,
                                    source_is_video=self._frames.is_video))
            self._saver.save(output, encode_image(face.aligned.face, ".png", metadata=meta))
            if not self._arguments.large and self._is_legacy:
                face.thumbnail = generate_thumbnail(face.aligned.face, size=96, quality=60)
                self._alignments.data[filename]["faces"][idx] = face.to_alignment()
                  length = int(((len_x ** 2) + (len_y ** 2)) ** 0.5)
              sizes.append(length)
          logger.trace("sizes: '%s'", sizes)
          return sizes









keep keep keep keep replace replace replace replace replace replace replace replace replace
 Update extracted faces to use PNG EXIF data (#1123)

Documentation
  - Update Usage.md, align.rst and image.rst
lib.image.py
  - read_image - Remove hash return, add metadata return
  - Remove read_image_hash functions
  - Add read_image_meta functios
  - Replace encode_image_with_hash with encode_image (to store metadata)
  - Add png meta reading and writing functions
  - Update Image Loaders/Savers to handle metadata rather than hashes
lib.training_data
  - Naming updates to remove references to hashes
lib.align.Alignments
  - Add versioning notes
  - Increment alignments version to 2.1
  - Deprecate hashing lookup functions
  - Replace filter_hashes with filter_faces
lib.align.detected_face
  - DetectedFace
    - Remove hash property
    - Add png header data serializing/deserializing functions
  - Mask
    - Add png header data serializing/deserializing functions
  - add update_legacy_png_header function to update png meta data
lib.cli.args - Deprecate alignments files for training
- plugins.train.trainer
  - Update alignments/mask code to read png header data
- scripts.convert
  - Aligned images folder - read data from png headers
- scripts.extract
  - Write png header information and no longer store hash of face
- tools.alignments
  - remove leftover-faces, merge and update-hashes jobs
  - Update jobs to use png meta data rather than hashes
- tools.manual
  - Update extract code to output png meta data and don't store hashes
  - Perform check on launch that tool is not pointing at a faces folder
tools.mask
  - Update to use png meta data
tools.sort
  - Update to use png meta data 
tools/alignments/media.py