Created
April 2, 2020 06:25
-
-
Save monkeydone/98966706051c1a95a2fd36314cf89b55 to your computer and use it in GitHub Desktop.
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
#!/bin/env python | |
from PIL import Image | |
from os.path import realpath | |
from os import getcwd | |
from sys import argv | |
from setproctitle import setproctitle | |
name = 'pic2pdf' | |
setproctitle(name) | |
def pic2pdf(imglist, output): | |
""" Create pdf file from pictures | |
Args: | |
imglist (list): list of pictures path | |
output (str): name of the output pdf file | |
""" | |
pathlist = [realpath(img) for img in imglist] | |
image = Image.open(pathlist[0]) | |
images = [Image.open(path) for path in pathlist[1:]] | |
image.save(output, "PDF" ,resolution=100.0, save_all=True, append_images=images) | |
help_text = """pic2pdf | |
Script using Python Image Library that put a list of pictures into one pdf file. | |
SYNTAX: | |
pic2pdf pic1 pic2 ... picN file.pdf \n | |
Copyright (C) 2018 Pellegrino Prevete. | |
This is free software; see the source code for copying conditions. | |
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or | |
FITNESS FOR A PARTICULAR PURPOSE. | |
""" | |
if len(argv) == 1 or "--help" in argv: | |
print(help_text) | |
else: | |
imglist = argv[1:-1] | |
output = argv[-1] | |
# pic2pdf(imglist, output1) | |
from os import listdir | |
list1 = listdir(".") | |
# for i in list1: | |
# print i | |
pic2pdf(list1,output) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment