Skip to content

Instantly share code, notes, and snippets.

@psyaro
Created November 28, 2019 21:32
Show Gist options
  • Save psyaro/ee661d1a5064efed8bc4963d452daedd to your computer and use it in GitHub Desktop.
Save psyaro/ee661d1a5064efed8bc4963d452daedd to your computer and use it in GitHub Desktop.
picture2pdf
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