Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- from pathlib import Path
- from natsort import natsorted
- path = Path.cwd() if __name__ == "__main__" else Path.cwd() / "book"
- un_images_list = list(Path(path).glob("*.jpg"))
- images_list = natsorted([fr"{i.as_posix()}" for i in un_images_list])
- def create_pdf(filename: str):
- images = []
- for image in images_list:
- img_opn = Image.open(image)
- img_opn = img_opn.convert("RGB")
- images.append(img_opn)
- print(f"{image} добавлена")
- img = Image.open(un_images_list[0])
- img.save(f"{filename}.pdf", save_all=True, append_images=images)
- print("ПДФ сохранен!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement