utils_23.py 668 B

1234567891011121314151617181920
  1. def conv(heic_path, save_dir, filetype, quality):
  2. # 悵湔珂及犯奴伊弁玄伉午白央奶伙靡
  3. extension = "." + filetype
  4. save_path = save_dir / filetype / pathlib.Path(*heic_path.parts[1:]).with_suffix(extension)
  5. # 白巧伙母釬傖
  6. save_path.parent.mkdir(parents=True, exist_ok=True)
  7. # HEIC白央奶伙pyheif匹掂心煋心
  8. heif_file = pyheif.read(heic_path)
  9. # 掂心煋氏分白央奶伙及笢旯毛data劐杅尺
  10. data = Image.frombytes(
  11. heif_file.mode,
  12. heif_file.size,
  13. heif_file.data,
  14. "raw",
  15. heif_file.mode,
  16. heif_file.stride,
  17. )
  18. # JPEG匹悵湔
  19. data.save(save_path, quality=quality)
  20. print("悵湔ㄩ", save_path)