from PIL import Image
import random
def converter(path, outputfname):
if len(path) == 1:
img = Image.open(path[0])
img.save('/root/Рабочий стол/f/YABAL.PDF', "PDF" ,resolution=100.0,)
else:
img_list = list()
img1 = Image.open(path[0])
del path[0]
for file in path:
i = random.randint(2, 99999)
code = '''img'''+str(i)+'''=Image.open("'''+str(file)+'''")\nimg_list.append(img'''+str(i)+''')'''
exec(code)
img1.save(outputfname, "PDF" ,resolution=100.0, save_all=True, append_images=img_list)
path = ['/root/Рабочий стол/23.jpg', '/root/Рабочий стол/workbench.jpg']
converter(path, "/root/Рабочий стол/f/YABAL.PDF")