code: def frompil(cls, image, compression=Compression.PACK_BITS):
          
          header = cls._make_header(image.mode, image.size)
          # TODO: Add default metadata.
          # TODO: Perhaps make this smart object.
          image_data = ImageData(compression=compression)
          image_data.set_data([channel.tobytes() for channel in image.split()],
                              header)
          return cls(PSD(
              header=header,
              image_data=image_data,
              image_resources=ImageResources.new(),
          ))
docs: Create a new PSD document from PIL Image.
  
          :param image: PIL Image object.
          :param compression: ImageData compression option. See
              :py:class:`~psd_tools.constants.Compression`.
          :return: A :py:class:`~psd_tools.api.psd_image.PSDImage` object.