MCPcopy Index your code
hub / github.com/lincolnloop/python-qrcode / new_image

Method new_image

qrcode/image/pil.py:12–44  ·  view source on GitHub ↗
(self, **kwargs)

Source from the content-addressed store, hash-verified

10 kind = "PNG"
11
12 def new_image(self, **kwargs):
13 if not Image:
14 raise ImportError("PIL library not found.")
15
16 back_color = kwargs.get("back_color", "white")
17 fill_color = kwargs.get("fill_color", "black")
18
19 try:
20 fill_color = fill_color.lower()
21 except AttributeError:
22 pass
23
24 try:
25 back_color = back_color.lower()
26 except AttributeError:
27 pass
28
29 # L mode (1 mode) color = (r*299 + g*587 + b*114)//1000
30 if fill_color == "black" and back_color == "white":
31 mode = "1"
32 fill_color = 0
33 if back_color == "white":
34 back_color = 255
35 elif back_color == "transparent":
36 mode = "RGBA"
37 back_color = None
38 else:
39 mode = "RGB"
40
41 img = Image.new(mode, (self.pixel_size, self.pixel_size), back_color)
42 self.fill_color = fill_color
43 self._idr = ImageDraw.Draw(img)
44 return img
45
46 def drawrect(self, row, col):
47 box = self.pixel_box(row, col)

Callers

nothing calls this directly

Calls 1

getMethod · 0.80

Tested by

no test coverage detected