Skip to content

Instantly share code, notes, and snippets.

@cosmicqbit
Last active October 16, 2022 18:02
Show Gist options
  • Select an option

  • Save cosmicqbit/2dc504e6d2f744fef6dc556e3a29fed4 to your computer and use it in GitHub Desktop.

Select an option

Save cosmicqbit/2dc504e6d2f744fef6dc556e3a29fed4 to your computer and use it in GitHub Desktop.
Batch Convert Images to PDF
from email.mime import base
from PIL import Image
import os
image_list = []
files = os.listdir()
image_files = []
for i in range(len(files)):
if files[i].endswith(".png"):
image_files.append(files[i])
for i in range(len(image_files)):
image = Image.open(image_files[i]).convert('RGB')
image_list.append(image)
if i == 0:
image_list.pop()
base_img = image
base_img.save('compiled-by-li.pdf', save_all=True, append_images=image_list)
@cosmicqbit
Copy link
Copy Markdown
Author

Prerequisites

pip install PIL

Run

python run.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment