def create_captcha_image(self, chars, color, background):
image = Image.new('<STR_LIT>', (self._width, self._height), background)<EOL>draw = Draw(image)<EOL>def _draw_character(c):<EOL><INDENT>font = random.choice(self.truefonts)<EOL>w, h = draw.textsize(c, font=font)<EOL>dx = random.randint(<NUM_LIT:0>, <NUM_LIT:4>)<EOL>dy = random.randint(<NUM_LIT:0>, <NUM_LIT:6>)<EOL>im = Image.new('<STR_LIT>', (w + dx, h + dy))<EOL>Draw(im).text((dx, dy), c, font=font, fill=color)<EOL>im = im.crop(im.getbbox())<EOL>im = im.rotate(random.uniform(-<NUM_LIT:30>, <NUM_LIT:30>), Image.BILINEAR, expand=<NUM_LIT:1>)<EOL>dx = w * random.uniform(<NUM_LIT:0.1>, <NUM_LIT>)<EOL>dy = h * random.uniform(<NUM_LIT>, <NUM_LIT>)<EOL>x1 = int(random.uniform(-dx, dx))<EOL>y1 = int(random.uniform(-dy, dy))<EOL>x2 = int(random.uniform(-dx, dx))<EOL>y2 = int(random.uniform(-dy, dy))<EOL>w2 = w + abs(x1) + abs(x2)<EOL>h2 = h + abs(y1) + abs(y2)<EOL>data = (<EOL>x1, y1,<EOL>-x1, h2 - y2,<EOL>w2 + x2, h2 + y2,<EOL>w2 - x2, -y1,<EOL>)<EOL>im = im.resize((w2, h2))<EOL>im = im.transform((w, h), Image.QUAD, data)<EOL>return im<EOL><DEDENT>images = []<EOL>for c in chars:<EOL><INDENT>if random.random() > <NUM_LIT:0.5>:<EOL><INDENT>images.append(_draw_character("<STR_LIT:U+0020>"))<EOL><DEDENT>images.append(_draw_character(c))<EOL><DEDENT>text_width = sum([im.size[<NUM_LIT:0>] for im in images])<EOL>width = max(text_width, self._width)<EOL>image = image.resize((width, self._height))<EOL>average = int(text_width / len(chars))<EOL>rand = int(<NUM_LIT> * average)<EOL>offset = int(average * <NUM_LIT:0.1>)<EOL>for im in images:<EOL><INDENT>w, h = im.size<EOL>mask = im.convert('<STR_LIT:L>').point(table)<EOL>image.paste(im, (offset, int((self._height - h) / <NUM_LIT:2>)), mask)<EOL>offset = offset + w + random.randint(-rand, <NUM_LIT:0>)<EOL><DEDENT>if width > self._width:<EOL><INDENT>image = image.resize((self._width, self._height))<EOL><DEDENT>return image<EOL>
Create the CAPTCHA image itself.

        :param chars: text to be generated.
        :param color: color of the text.
        :param background: color of the background.

        The color should be a tuple of 3 numbers, such as (0, 255, 255).