Created
November 28, 2019 21:32
-
-
Save psyaro/ee661d1a5064efed8bc4963d452daedd to your computer and use it in GitHub Desktop.
picture2pdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import img2pdf | |
from pathlib import Path | |
import ffmpy | |
from glob import glob | |
import os | |
def main(): | |
names = [] | |
for x in glob('*.jpg') + glob('*.png'): | |
x = os.path.splitext(x) | |
if x[1] == '.jpg': | |
ff = ffmpy.FFmpeg( | |
inputs={f'{x[0]}{x[1]}' : None}, | |
outputs={f'{x[0]}.png' : None} | |
) | |
ff.run() | |
os.remove(x[0] + x[1]) | |
name = x[0].split('_')[0] | |
if name not in names: names.append(name) | |
for name in names: | |
pdf = name + '.pdf' | |
filelist = sorted([x for x in glob(f'{name}_*.png')]) | |
print(filelist) | |
if not os.path.exists(pdf): | |
with open(pdf, "wb") as f: f.write(img2pdf.convert(filelist)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment