Skip to content

Instantly share code, notes, and snippets.

@quul
Created September 10, 2022 07:49
Show Gist options
  • Save quul/d4b113812be4576d2b96c0c57fb8d8c6 to your computer and use it in GitHub Desktop.
Save quul/d4b113812be4576d2b96c0c57fb8d8c6 to your computer and use it in GitHub Desktop.
A simple python script to cover floder/name/*.jpg to PDF by https://github.com/myollie/img2pdf
from logging import root
import img2pdf
import os
def main():
root_dir = input("Please input the root dictionary of the file:")
if root_dir == "":
root_dir = os.getcwd()
os.chdir(root_dir)
folders = os.listdir()
folders.remove('outputs') # For de-duplicated.
for folder_name in folders:
try:
os.chdir(folder_name)
images = list(filter(lambda x:x.endswith('.jpeg'),os.listdir()))
images = list(map(lambda x:int(x.split('.')[0]),images))
images.sort()
images = list(map(lambda x: str(x)+'.jpeg',images))
# images= list(map(lambda x:x+'.jpg',list(map(lambda x:x.split('.')[0],filter(lambda x:x.endswith('jpg'), os.listdir()))).sort()))
with open('../outputs/'+folder_name+'.pdf','wb') as f:
f.write(img2pdf.convert(images))
os.chdir('..')
except:
pass
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment