MCPcopy Index your code
hub / github.com/geekcomputers/Python / convertPictures

Method convertPictures

image2pdf/image2pdf.py:69–110  ·  view source on GitHub ↗

Convert pictures according the following: * If pictures = 0 -> Skip * If pictures = 1 -> use all * Else -> allow user to pick pictures Then determine to merge all or one pdf

(self)

Source from the content-addressed store, hash-verified

67 return pictures
68
69 def convertPictures(self):
70 """
71 Convert pictures according the following:
72 * If pictures = 0 -> Skip
73 * If pictures = 1 -> use all
74 * Else -> allow user to pick pictures
75
76 Then determine to merge all or one pdf
77 """
78
79 pictures = self.getPictures()
80 totalPictures = len(pictures) if pictures else 0
81
82 if totalPictures == 0:
83 return
84
85 elif totalPictures >= 2:
86 pictures = self.selectPictures(pictures)
87
88 if self.isMergePDF:
89 # All pics in one pdf.
90 for picture in pictures:
91 self.pictures.append(
92 Image.open(f"{self.directory}\\{picture}").convert("RGB")
93 )
94 self.save()
95
96 else:
97 # Each pic in seperate pdf.
98 for picture in pictures:
99 self.save(
100 Image.open(f"{self.directory}\\{picture}").convert("RGB"),
101 picture,
102 False,
103 )
104
105 # Reset to default value for next run
106 self.isMergePDF = True
107 self.pictures = []
108 print(f"\n{'#' * 30}")
109 print(" Done! ")
110 print(f"{'#' * 30}\n")
111
112 def save(self, image=None, title="All-PDFs", isMergeAll=True):
113 # Save all to one pdf or each in seperate file

Callers 1

image2pdf.pyFile · 0.80

Calls 5

getPicturesMethod · 0.95
selectPicturesMethod · 0.95
saveMethod · 0.95
convertMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected