Beispiel #1
0
def display_bounding_boxes_within_notebook(page_num,
                                           extractor,
                                           blocks,
                                           alternatecolors=False,
                                           color=Color('blue')):
    """
    Displays each of the bounding boxes passed in 'boxes' on an image of the pdf
    pointed to by pdf_file
    boxes is a list of 5-tuples (page, top, left, bottom, right)
    """
    elems = extractor.elems[page_num]
    page_width, page_height = int(elems.layout.width), int(elems.layout.height)
    img = pdf_to_img(extractor.pdf_file, page_num, page_width, page_height)
    draw = Drawing()
    draw.fill_color = Color('rgba(0, 0, 0, 0)')
    draw.stroke_color = color
    for block in blocks:
        top, left, bottom, right = block[-4:]
        if alternatecolors:
            draw.stroke_color = Color('rgba({},{},{}, 1)'.format(
                str(np.random.randint(255)), str(np.random.randint(255)),
                str(np.random.randint(255))))
        draw.rectangle(left=float(left),
                       top=float(top),
                       right=float(right),
                       bottom=float(bottom))
        draw(img)
    return img
Beispiel #2
0
 def display_bounding_boxes(self, page_num, bboxes, alternate_colors=True):
     elems = self.elems[page_num]
     page_width, page_height = int(elems.layout.width), int(elems.layout.height)
     img = pdf_to_img(self.pdf_file, page_num, page_width, page_height)
     draw = Drawing()
     draw.fill_color = Color("rgba(0, 0, 0, 0)")
     color = Color("blue")
     draw.stroke_color = color
     for block in bboxes:
         top, left, bottom, right = block[-4:]
         draw.stroke_color = Color(
             "rgba({},{},{}, 1)".format(
                 str(np.random.randint(255)),
                 str(np.random.randint(255)),
                 str(np.random.randint(255)),
             )
         )
         draw.rectangle(
             left=float(left),
             top=float(top),
             right=float(right),
             bottom=float(bottom),
         )
     draw(img)
     return img
Beispiel #3
0
def display_bounding_boxes(img,
                           blocks,
                           alternatecolors=False,
                           color=Color("blue")):
    """
    Displays each of the bounding boxes passed in 'boxes' on an image of the pdf
    pointed to by pdf_file
    boxes is a list of 5-tuples (page, top, left, bottom, right)
    """
    draw = Drawing()
    draw.fill_color = Color("rgba(0, 0, 0, 0)")
    draw.stroke_color = color
    for block in blocks:
        top, left, bottom, right = block[-4:]
        if alternatecolors:
            draw.stroke_color = Color("rgba({},{},{}, 1)".format(
                str(np.random.randint(255)),
                str(np.random.randint(255)),
                str(np.random.randint(255)),
            ))
        draw.rectangle(left=float(left),
                       top=float(top),
                       right=float(right),
                       bottom=float(bottom))
        draw(img)
    display(img)
Beispiel #4
0
 def display_boxes(self, pdf_file, boxes, alternate_colors=False):
     """
     Displays each of the bounding boxes passed in 'boxes' on images of the pdf
     pointed to by pdf_file
     boxes is a list of 5-tuples (page, top, left, bottom, right)
     """
     imgs = []
     colors = [Color('blue'), Color('red')]
     boxes_per_page = defaultdict(int)
     boxes_by_page = defaultdict(list)
     for i, (page, top, left, bottom, right) in enumerate(boxes):
         boxes_per_page[page] += 1
         boxes_by_page[page].append((top, left, bottom, right))
     for i, page_num in enumerate(boxes_per_page.keys()):
         img = pdf_to_img(pdf_file, page_num)
         draw = Drawing()
         draw.fill_color = Color('rgba(0, 0, 0, 0.0)')
         for j, (top, left, bottom,
                 right) in enumerate(boxes_by_page[page_num]):
             draw.stroke_color = colors[
                 j % 2] if alternate_colors else colors[0]
             draw.rectangle(left=left, top=top, right=right, bottom=bottom)
         draw(img)
         imgs.append(img)
     return imgs
Beispiel #5
0
async def remix_meeme(upper_text, lower_text, picture_name, endname):
    main_image = remiximage(filename=picture_name)
    main_image.resize(
        1024,
        int(((main_image.height * 1.0) / (main_image.width * 1.0)) * 1024.0))
    upper_text = "\n".join(wrap(upper_text,
                                get_warp_length(main_image.width))).upper()
    lower_text = "\n".join(wrap(lower_text,
                                get_warp_length(main_image.width))).upper()
    lower_margin = MARGINS[lower_text.count("\n")]
    text_draw = Drawing()
    text_draw.font = join(getcwd(),
                          "userbot/utils/styles/MutantAcademyStyle.ttf")
    text_draw.font_size = 100
    text_draw.text_alignment = "center"
    text_draw.stroke_color = Color("black")
    text_draw.stroke_width = 3
    text_draw.fill_color = Color("white")
    if upper_text:
        text_draw.text((main_image.width) // 2, 80, upper_text)
    if lower_text:
        text_draw.text((main_image.width) // 2,
                       main_image.height - lower_margin, lower_text)
    text_draw(main_image)
    main_image.save(filename=endname)
Beispiel #6
0
def generate_meme(upper_text, lower_text, picture_name_orig,
                  picture_name_target):
    main_image = Image(filename=join(TEMPLATES_FOLDER, picture_name_orig))
    main_image.resize(
        1024,
        int(((main_image.height * 1.0) / (main_image.width * 1.0)) * 1024.0))

    upper_text = "\n".join(wrap(upper_text,
                                get_warp_length(main_image.width))).upper()
    lower_text = "\n".join(wrap(lower_text,
                                get_warp_length(main_image.width))).upper()
    lower_margin = MARGINS[lower_text.count("\n")]

    text_draw = Drawing()

    text_draw.font = join(getcwd(), "impact.ttf")
    text_draw.font_size = 70
    text_draw.text_alignment = "center"
    text_draw.stroke_color = Color("black")
    text_draw.stroke_width = 3
    text_draw.fill_color = Color("white")

    if upper_text:
        text_draw.text(int(main_image.width / 2), 80, upper_text)
    if lower_text:
        text_draw.text(int(main_image.width / 2),
                       main_image.height - lower_margin, lower_text)

    text_draw(main_image)

    main_image.save(filename=join(getcwd(), MEME_FOLDER, picture_name_target))
Beispiel #7
0
	def generate_track(self) :

		draw = Drawing()
		draw.stroke_width = 2
		draw.stroke_color = Color('red')
		draw.fill_color = Color('transparent')

		points = []

		# Loop over the coordinates to create a list of tuples
		for coords in self.geojson['coordinates'] :
			pt = Point(coords[0], coords[1])
			pt.project(self.rendering_zoom)
			x, y = pt.get_xy()
			x = round(x - (self.minxtile * 256))
			y = round(y - (self.minytile * 256))
			points.append((x, y))

		# draw the polyline
		draw.polyline(points)

		# apply to the image
		draw(self.img)

		# self.rendering_bounds.nw.project(self.rendering_zoom)
		x = int(self.rendering_bounds.nw.tile_x - self.minxtile)
		y = int(self.rendering_bounds.nw.tile_y - self.minytile)

		self.crop(x, y)
		self.img.format = 'jpeg'
		# self.img.save(filename='image.jpg')
		return self.img.make_blob('jpeg')
Beispiel #8
0
def generate_images(im_ch, man_ch):
    data = pd.read_excel('VeinsCoordsV05.xlsx')
    ch = 0
    print('Сгенерированные изображения:', end=' ')
    for i in range(1, man_ch + 1):
        oneman_im_ch = 1
        ch += 1
        filename = create_filename(i)
        draw_img = Drawing()
        draw_img.stroke_color = Color("white")
        img = WandImage(width=334, height=118, background=Color("black"))
        img.save(filename=filename)
        for j in func_dict.keys():
            vein = data.iloc[j - 2, 7:]
            start_coord, finish_coord = data.iloc[j - 2, 1], data.iloc[j - 2,
                                                                       3]
            x, y = prepare_data(vein)
            popt, _ = curve_fit(func_dict.get(j), x, y)
            for k in range(popt.shape[0]):
                a, b = find_random_diap(popt[k], j)
                popt[k] = random.uniform(a, b)
            if j in vein_width_dict.keys():
                brush_width = random.uniform(
                    vein_width_dict.get(j)[0],
                    vein_width_dict.get(j)[1])
            else:
                brush_width = random.uniform(1, 1.5)
            create_line_img(start_coord, finish_coord, brush_width, popt, img,
                            filename)
        img.blur(radius=0, sigma=1)
        img.crop(46, 25, 321, 90)
        img.save(filename=filename)
        oneman_vein_name = filename
        print(ch, end=' ')
        while (oneman_im_ch < im_ch // man_ch) or (
            (ch + im_ch % man_ch == im_ch) and (im_ch % man_ch)):
            img = WandImage(filename=oneman_vein_name)
            x1_crop = random.randint(0, 40)
            y1_crop = random.randint(0, 2)
            x2_crop = random.randint(265, 275)
            y2_crop = random.randint(60, 63)
            if random.random() >= 0.4:
                alpha = random.randint(-2, 2)
                img.rotate(alpha, background=Color('black'))
            img.crop(x1_crop, y1_crop, x2_crop, y2_crop)
            if random.random() >= 0.5:
                rad = random.randint(1, 10)
                alpha = random.randint(-45, 45)
                img.motion_blur(radius=rad, sigma=8, angle=alpha)
            filename = oneman_vein_name.replace(
                '.png', '_' + str(oneman_im_ch) + '.png')
            img.save(filename=filename)
            oneman_im_ch += 1
            ch += 1
            print(ch, end=' ')
    print('')
    print('Изображения сгенерированы')
Beispiel #9
0
 def draw_watermark(self, img):
     watermark_draw = Drawing()
     watermark_draw.stroke_color = Color('black')
     watermark_draw.font = os.path.join(os.path.dirname(__file__), "Colombia-Regular.ttf")
     watermark_draw.font_size = 3 * POINT_PER_MM
     watermark_draw.text_antialias = True
     metrics = watermark_draw.get_font_metrics(img, WATERMARK)
     watermark_draw.text(max(0, math.floor((POINT_PER_MM * self.paper['width']) - metrics.text_width)),
                         max(0, math.floor((POINT_PER_MM * self.paper['height']) - metrics.text_height * 2)),
                         WATERMARK)
     watermark_draw.draw(img)
def create_kernel(w=3, h=3):
	k = Image(width=w * kernel_size + 2, height=h * kernel_size + 2)
	
	draw = Drawing()
	draw.fill_color = Color("white")
	draw.stroke_color = Color("black")

	for y in xrange(0,h):
		for x in xrange(0,w):
			draw.rectangle(left=x*kernel_size, top=y*kernel_size,
							width=kernel_size, height=kernel_size)
			draw(k)

	return k
def create_kernel(w=3, h=3):
    k = Image(width=w * kernel_size + 2, height=h * kernel_size + 2)

    draw = Drawing()
    draw.fill_color = Color("white")
    draw.stroke_color = Color("black")

    for y in xrange(0, h):
        for x in xrange(0, w):
            draw.rectangle(left=x * kernel_size,
                           top=y * kernel_size,
                           width=kernel_size,
                           height=kernel_size)
            draw(k)

    return k
Beispiel #12
0
def generate_meme(upper_text, lower_text, picture_name):
    MEME_FOLDER = "memes"
    MARGINS = [25, 65, 100, 135, 170]

    if not exists(join(getcwd(), MEME_FOLDER)):
        mkdir(join(getcwd(), MEME_FOLDER))

    main_image = Image(filename=picture_name)
    main_image.resize(
        500, int(
            ((main_image.height * 1.0) / (main_image.width * 1.0)) * 500.0))

    upper_text = "\n".join(wrap(upper_text,
                                get_warp_length(main_image.width))).upper()
    lower_text = "\n".join(wrap(lower_text,
                                get_warp_length(main_image.width))).upper()
    lower_margin = MARGINS[lower_text.count("\n")]

    text_draw = Drawing()

    text_draw.font = join(getcwd(), "impact.ttf")
    text_draw.font_size = 40
    text_draw.text_alignment = "center"
    text_draw.stroke_color = Color("black")
    text_draw.stroke_width = 3
    text_draw.fill_color = Color("white")

    if upper_text:
        text_draw.text(main_image.width / 2, 40, upper_text)
    if lower_text:
        text_draw.text(main_image.width / 2, main_image.height - lower_margin,
                       lower_text)

    text_draw(main_image)

    outname = "[MEME] " + picture_name
    main_image.save(filename=join(getcwd(), MEME_FOLDER, outname))

    # if sys.platform.startswith('darwin'):
    #     system('open "%s"' % (join(getcwd(), MEME_FOLDER, outname)))
    # elif name == 'nt':
    #     system('start "%s"' % (join(getcwd(), MEME_FOLDER, outname)))
    # elif name == 'posix':
    #     system('xdg-open "%s"' % (join(getcwd(), MEME_FOLDER, outname)))
    # else:
    #     pass
    return MEME_FOLDER + '/' + outname
Beispiel #13
0
    def make_og_meme(self, top, bottom):
        """Generate an OG Meme
        """

        wand_t = Image(blob=self.image.read())
        MARGINS = [50, 130, 200, 270, 340]

        # Set a minimum size
        wand_t.resize(
            1024, int(((wand_t.height * 1.0) / (wand_t.width * 1.0)) * 1024.0))

        use_top = True
        use_bottom = True

        if top == ' ':
            use_top = False
        if bottom == ' ':
            use_bottom = False

        if use_top:
            upper_text = "\n".join(
                wrap(top, self.get_warp_length(int(wand_t.width)))).upper()
        if use_bottom:
            lower_text = "\n".join(
                wrap(bottom, self.get_warp_length(int(wand_t.width)))).upper()
            lower_margin = MARGINS[lower_text.count("\n")]

        text_draw = Drawing()

        text_draw.font = "fonts/Anton-Regular.ttf"
        text_draw.font_size = 70
        text_draw.text_alignment = "center"
        text_draw.stroke_color = Color("black")
        text_draw.stroke_width = 3
        text_draw.fill_color = Color("white")

        if use_top:
            text_draw.text(int(wand_t.width / 2), 80, upper_text)

        if use_bottom:
            text_draw.text(int(wand_t.width / 2),
                           int(wand_t.height - lower_margin), lower_text)

        text_draw(wand_t)

        return (wand_t)
Beispiel #14
0
 def display_boxes(self,
                   tree,
                   html_path,
                   filename_prefix,
                   alternate_colors=False):
     """
     Displays each of the bounding boxes passed in 'boxes' on images of the pdf
     pointed to by pdf_file
     boxes is a list of 5-tuples (page, top, left, bottom, right)
     """
     imgs = []
     colors = {
         "section_header": Color('blue'),
         "figure": Color('green'),
         "figure_caption": Color('green'),
         "table_caption": Color('red'),
         "list": Color('yellow'),
         "paragraph": Color('gray'),
         "table": Color('red'),
         "header": Color("brown")
     }
     for i, page_num in enumerate(tree.keys()):
         img = self.pdf_to_img(page_num)
         draw = Drawing()
         draw.fill_color = Color('rgba(0, 0, 0, 0.0)')
         for clust in tree[page_num]:
             for (pnum, pwidth, pheight, top, left, bottom,
                  right) in tree[page_num][clust]:
                 draw.stroke_color = colors[clust]
                 draw.rectangle(left=left,
                                top=top,
                                right=right,
                                bottom=bottom)
                 draw.push()
                 draw.font_size = 20
                 draw.font_weight = 10
                 draw.fill_color = colors[clust]
                 if int(left) > 0 and int(top) > 0:
                     draw.text(x=int(left), y=int(top), body=clust)
                 draw.pop()
         draw(img)
         img.save(filename=html_path + filename_prefix + "_page_" + str(i) +
                  '.png')
         imgs.append(img)
     return imgs
Beispiel #15
0
def generar_meme(texto, nombre_imagen):
    imagen = Image(filename=nombre_imagen)
    imagen.resize(1024,
                  int(((imagen.height * 1.0) / (imagen.width * 1.0)) * 1024.0))

    texto = "\n".join(wrap(texto, get_length(imagen.width))).upper()

    text_draw = Drawing()

    text_draw.font = os.path.join(os.getcwd(), "impact.ttf")
    text_draw.font_size = 60
    text_draw.text_alignment = "center"
    text_draw.stroke_color = Color("black")
    text_draw.stroke_width = 3
    text_draw.fill_color = Color("white")

    if texto:
        text_draw.text(imagen.width * 60//100, imagen.height * 55//100, texto)

    text_draw(imagen)

    imagen.save(filename=os.path.join(os.getcwd(), "memes", "meme.jpg"))
Beispiel #16
0
def create_line_img(x_start, x_finish, brush_width, params, img, filename):
    step = 1.01
    draw_img = Drawing()
    draw_img.stroke_color = Color("white")
    draw_img.fill_color = Color("white")
    draw_img.stroke_width = brush_width
    if x_start > x_finish:
        buf = x_start
        x_start = x_finish
        x_finish = buf
    x = x_start + step
    for i in range(3):
        while x < x_finish:
            x1 = x - step
            y1 = chosen_func(x1, params)
            y2 = chosen_func(x, params)
            draw_img.line((x1, y1), (x, y2))
            x = x + 2 * step
        step -= 0.5
        x = x_start + step
    draw_img.draw(img)
    img.save(filename=filename)
Beispiel #17
0
 def _caption_akari(self):
     caption = 'わぁい{0} あかり{0}大好き'.format(self.text)
     drawing = Drawing()
     drawing.font = 'assets/fonts/rounded-mgenplus-1c-bold.ttf'
     drawing.font_size = self.width / 15
     text = fill(caption, 23)
     drawing.gravity = 'south'
     drawing.text_interline_spacing = drawing.font_size / -5
     offset = max(self.width / 400, 2)
     # first the shadow
     drawing.translate(offset, -offset)
     drawing.fill_color = Color('#000')
     drawing.fill_opacity = 0.5
     drawing.text(0, 0, text)
     # then the text
     drawing.translate(-offset, offset)
     drawing.fill_color = Color('#fff')
     drawing.fill_opacity = 1.0
     drawing.stroke_color = Color('#000')
     drawing.stroke_width = max(self.width / 600, 1)
     drawing.text(0, 0, text)
     return caption, drawing
Beispiel #18
0
def generate(count):
    # ---------------get three colors-------------------------------
    colorString = random.choice(result)
    color = []
    for i in colorString:
        color += [int(i)]
    # for i in range(len(color)):
    #     color[i] = math.floor(color[i]/255*65535)
    color1 = color[0:3]
    color2 = color[3:6]
    color3 = color[6:9]
    # --------------------------------------------------------------

    # ----------get the base layer texture--------------------------
    Scenes = pathwalk('./SceneData')

    randomScene = random.choice(Scenes)
    randomScene = randomScene[0] + '/' + randomScene[1]
    print(randomScene)
    randomSceneImage = Image(filename=randomScene)

    widthRange = randomSceneImage.size[0] - 100
    heightRange = randomSceneImage.size[1] - 32

    randomSceneImage.crop(left=random.randint(0, widthRange),
                          top=random.randint(0, heightRange),
                          width=100,
                          height=32)
    # randomSceneImage.save(filename='.\\photoWand\\'+str(j+1) + '_texture.jpg')
    # --------------------------------------------------------------

    # ----------create the base layer, base texture +base color-----

    baseImage = Image(
        width=100,
        height=32,
        background=Color('rgb(' + str(color1[0]) + ',' + str(color1[1]) + ',' +
                         str(color1[2]) + ')'))

    # print('base_color = ' + 'rgb('+str(color1[0])+','+str(color1[1])+','+str(color1[2])+')')
    baseImage.composite_channel(channel='undefined',
                                image=randomSceneImage,
                                operator='blend',
                                left=0,
                                top=0)
    baseImage.gaussian_blur(4, 10)
    baseImage.resolution = (96, 96)
    # --------------------------------------------------------------

    # -----generate font--------------------------------------------
    word = randomWords()
    fonts = pathwalk('./fonts/font_en/')
    randomFont = random.choice(fonts)
    randomFont = randomFont[0] + randomFont[1]

    initialPointsize = 45

    draw = Drawing()
    draw.font = randomFont

    tmp = int(math.floor(abs(random.gauss(0, 1)) * 6))
    if random.randint(1, 2) == 1:
        rotateX = random.randint(0, tmp)
    else:
        rotateX = random.randint(360 - tmp, 360)

    draw.rotate(rotateX)
    # --------------------------------------------------------------
    # --------get suitable FontPointSize----------------------------
    draw.font_size = initialPointsize
    metric = draw.get_font_metrics(image=baseImage, text=word)

    while metric.text_width > 100 or metric.text_height > 36:
        initialPointsize -= 5
        draw.font_size = initialPointsize
        metric = draw.get_font_metrics(image=baseImage, text=word)
    # --------------------------------------------------------------

    # ----------italic----------------------------------------------
    if random.random() > 0.5:
        draw.font_style = 'italic'
    # --------------------------------------------------------------

    # ----------underline-------------------------------------------
    if random.random() > 0.5:
        draw.text_decoration = 'underline'
    # --------------------------------------------------------------

    # ----------gravity---------------------------------------------
    draw.gravity = 'center'
    # --------------------------------------------------------------

    # --------------shadow/border-----------------------------------
    if random.random() < 0.5:
        # shadow
        addx = math.ceil(random.gauss(0, 2))
        addy = math.ceil(random.gauss(0, 2))
        draw.fill_color = Color('black')
        draw.text(x=abs(int(addx)), y=abs(int(addy)), body=word)

    else:
        # border
        draw.stroke_color = Color('rgb(' + str(color3[0]) + ',' +
                                  str(color3[1]) + ',' + str(color3[2]) + ')')
        draw.stroke_width = math.ceil(initialPointsize / 10) - 1
    # --------------------------------------------------------------

    # ----------print word------------------------------------------
    draw.fill_color = Color('rgb(' + str(color2[0]) + ',' + str(color2[1]) +
                            ',' + str(color2[2]) + ')')
    draw.text(x=0, y=0, body=word)
    draw.draw(baseImage)
    # --------------------------------------------------------------

    # ------------gray----------------------------------------------
    baseImage.colorspace = 'gray'
    # --------------------------------------------------------------

    print(word)
    baseImage.save(filename='./photo_en/' + str(count + 1) + '_' + word +
                   '.jpg')
Beispiel #19
0
def makedrawing():
    draw = Drawing()
    draw.fill_color = Color('white')
    draw.stroke_color = Color('black')
    draw.stroke_width = 1
    return draw
Beispiel #20
0
def make_namecard(user_info_list, team_info, template):
    # check team directory exist(if not, make)
    path_team_dir = '/'.join((os.path.abspath(os.path.dirname(__file__)),
                              'deliverable', team_info['name']))
    if not os.path.isdir(path_team_dir):
        os.makedirs(path_team_dir)

    # check icon directory exist(if not, make)
    path_icon_dir = '/'.join((path_team_dir, 'icon'))
    if not os.path.isdir(path_icon_dir):
        os.makedirs(path_icon_dir)

    # check namecard directory exist(if not, make)
    path_card_dir = '/'.join((path_team_dir, 'namecard'))
    if not os.path.isdir(path_card_dir):
        os.makedirs(path_card_dir)

    # make plain card
    base = Image(width=template['width'],
                 height=template['height'],
                 background=Color('rgb(255, 255, 255)'))
    frame = Drawing()
    frame.stroke_color = Color('rgb(0, 0, 0)')
    frame.fill_color = Color('rgba(255, 255, 255, 0)')
    frame.rectangle(left=0,
                    top=0,
                    width=base.width - 1,
                    height=base.height - 1)
    frame(base)

    # draw team logo
    if template['logo']['display']:
        # check team icon exist offline(if not, get)
        path_logo_file = ''.join((path_team_dir, '/logo.jpg'))
        if not os.path.isfile(path_logo_file):
            icon_collector.get_image(team_info['icon'], path_logo_file)
        logo_draw = Image(filename=path_logo_file)
        logo_draw.resize(template['logo']['size'], template['logo']['size'])
        if template['logo']['align'] == 'left':
            logo_left = template['logo']['x']
        elif template['logo']['align'] == 'center':
            logo_left = template['logo']['x'] - int(
                template['logo']['size'] / 2)
        elif template['logo']['align'] == 'right':
            logo_left = template['logo']['x'] - template['logo']['size']
        logo_top = template['logo']['y']
        base.composite(logo_draw, logo_left, logo_top)

    # draw team name
    if template['team']['display']:
        team_draw = Drawing()
        if template['team']['font'] != 'default':
            team_draw.font = template['team']['font']
        if template['team']['size'] != 'default':
            team_draw.font_size = template['team']['size']
        mtr_team = team_draw.get_font_metrics(base, team_info['name'])
        if template['team']['align'] == 'left':
            team_left = template['team']['x']
        elif template['team']['align'] == 'center':
            team_left = template['team']['x'] - int(mtr_team.text_width / 2)
        elif template['team']['align'] == 'center':
            team_left = template['team']['x'] - int(mtr_team.text_width)
        team_top = template['team']['y'] + int(mtr_team.ascender)
        team_draw.text(team_left, team_top, team_info['name'])
        team_draw(base)

    #save dummy card
    base.save(filename=''.join((path_team_dir, '/dummy.png')))

    for user in user_info_list.values():
        base_clone = base.clone()
        # draw user icon
        if template['icon']['display']:
            # check user icon exist offline(if not, get)
            path_icon_file = ''.join(
                (path_icon_dir, '/', user['name'], '.png'))
            if not os.path.isfile(path_icon_file):
                icon_collector.get_image(user['icon'], path_icon_file)
            icon_draw = Image(filename=path_icon_file)
            icon_draw.resize(template['icon']['size'],
                             template['icon']['size'])
            if template['icon']['align'] == 'left':
                icon_left = template['icon']['x']
            elif template['icon']['align'] == 'center':
                icon_left = template['icon']['x'] - int(
                    template['icon']['size'] / 2)
            elif template['icon']['align'] == 'right':
                icon_left = template['icon']['x'] - template['icon']['size']
            icon_top = template['icon']['y']
            base_clone.composite(icon_draw, icon_left, icon_top)

        # draw real name
        if template['real']['display']:
            real_draw = Drawing()
            if template['real']['font'] != 'default':
                real_draw.font = template['real']['font']
            if template['real']['size'] != 'default':
                real_draw.font_size = template['real']['size']
            user_real_name = user['real_name']
            mtr_real = real_draw.get_font_metrics(base_clone, user_real_name)
            if mtr_real.text_width > template['real']['width']:
                user_real_name = user['real_name'].replace(' ', '\n')
                mtr_real = real_draw.get_font_metrics(base_clone,
                                                      user_real_name)
            if template['real']['align'] == 'left':
                real_left = template['real']['x']
            elif template['real']['align'] == 'center':
                real_left = template['real']['x'] - int(
                    mtr_real.text_width / 2)
            elif template['real']['align'] == 'center':
                real_left = template['real']['x'] - int(mtr_real.text_width)
            real_top = template['real']['y'] + int(mtr_real.ascender)
            real_draw.text(real_left, real_top, user_real_name)
            real_draw(base_clone)

        # draw name
        if template['name']['display']:
            name_draw = Drawing()
            if template['name']['font'] != 'default':
                name_draw.font = template['name']['font']
            if template['name']['size'] != 'default':
                name_draw.font_size = template['name']['size']
            user_name = ''.join(('@', user['name']))
            mtr_name = name_draw.get_font_metrics(base_clone, user_name)
            if template['name']['align'] == 'left':
                name_left = template['name']['x']
            elif template['name']['align'] == 'center':
                name_left = template['name']['x'] - int(
                    mtr_name.text_width / 2)
            elif template['name']['align'] == 'center':
                name_left = template['name']['x'] - int(mtr_name.text_width)
            name_top = template['name']['y'] + int(mtr_name.ascender)
            name_draw.text(name_left, name_top, user_name)
            name_draw(base_clone)

        # draw title
        if template['title']['display']:
            title_draw = Drawing()
            if template['title']['font'] != 'default':
                title_draw.font = template['title']['font']
            if template['title']['size'] != 'default':
                title_draw.font_size = template['title']['size']
            user_title = user['title']
            mtr_title = title_draw.get_font_metrics(base_clone, user_title)
            if template['title']['align'] == 'left':
                title_left = template['title']['x']
            elif template['title']['align'] == 'center':
                title_left = template['title']['x'] - int(
                    mtr_title.text_width / 2)
            elif template['title']['align'] == 'center':
                title_left = template['title']['x'] - int(mtr_title.text_width)
            title_top = template['title']['y'] + int(mtr_title.ascender)
            title_draw.text(title_left, title_top, user_title)
            title_draw(base_clone)

        base_clone.save(filename=''.join((path_card_dir, '/', user['name'],
                                          '.png')))
def generate(count):
    # ---------------get three colors-------------------------------
    colorString = random.choice(result)
    color = []
    for i in colorString:
        color += [int(i)]
    # for i in range(len(color)):
    #     color[i] = math.floor(color[i]/255*65535)
    color1 = color[0:3]
    color2 = color[3:6]
    color3 = color[6:9]
    # --------------------------------------------------------------

    # ----------get the base layer texture--------------------------
    Scenes = pathwalk('./SceneData')

    randomScene = random.choice(Scenes)
    randomScene = randomScene[0] + '/' + randomScene[1]
    print(randomScene)
    randomSceneImage = Image(filename=randomScene)

    widthRange = randomSceneImage.size[0] - 100
    heightRange = randomSceneImage.size[1] - 32

    randomSceneImage.crop(left=random.randint(0, widthRange), top=random.randint(0, heightRange), width=100, height=32)
    # randomSceneImage.save(filename='.\\photoWand\\'+str(j+1) + '_texture.jpg')
    # --------------------------------------------------------------

    # ----------create the base layer, base texture +base color-----

    baseImage = Image(width=100, height=32, background=Color('rgb('+str(color1[0])+','+str(color1[1])+','+str(color1[2])+')'))

    # print('base_color = ' + 'rgb('+str(color1[0])+','+str(color1[1])+','+str(color1[2])+')')
    baseImage.composite_channel(channel='undefined', image=randomSceneImage, operator='blend', left=0, top=0)
    baseImage.gaussian_blur(4, 10)
    baseImage.resolution = (96, 96)
    # --------------------------------------------------------------

    # -----generate font--------------------------------------------
    word = randomWords()
    fonts = pathwalk('./fonts/font_en/')
    randomFont = random.choice(fonts)
    randomFont = randomFont[0] + randomFont[1]

    initialPointsize = 45

    draw = Drawing()
    draw.font = randomFont

    tmp = int(math.floor(abs(random.gauss(0, 1))*6))
    if random.randint(1, 2) == 1:
        rotateX = random.randint(0, tmp)
    else:
        rotateX = random.randint(360-tmp, 360)

    draw.rotate(rotateX)
    # --------------------------------------------------------------
    # --------get suitable FontPointSize----------------------------
    draw.font_size = initialPointsize
    metric = draw.get_font_metrics(image=baseImage, text=word)

    while metric.text_width > 100 or metric.text_height > 36:
        initialPointsize -= 5
        draw.font_size = initialPointsize
        metric = draw.get_font_metrics(image=baseImage, text=word)
    # --------------------------------------------------------------

    # ----------italic----------------------------------------------
    if random.random() > 0.5:
        draw.font_style = 'italic'
    # --------------------------------------------------------------

    # ----------underline-------------------------------------------
    if random.random() > 0.5:
        draw.text_decoration = 'underline'
    # --------------------------------------------------------------

    # ----------gravity---------------------------------------------
    draw.gravity = 'center'
    # --------------------------------------------------------------

    # --------------shadow/border-----------------------------------
    if random.random() < 0.5:
        # shadow
        addx = math.ceil(random.gauss(0, 2))
        addy = math.ceil(random.gauss(0, 2))
        draw.fill_color = Color('black')
        draw.text(x=abs(int(addx)), y=abs(int(addy)), body=word)

    else:
        # border
        draw.stroke_color = Color('rgb('+str(color3[0])+','+str(color3[1])+','+str(color3[2])+')')
        draw.stroke_width = math.ceil(initialPointsize/10)-1
    # --------------------------------------------------------------

    # ----------print word------------------------------------------
    draw.fill_color = Color('rgb('+str(color2[0])+','+str(color2[1])+','+str(color2[2])+')')
    draw.text(x=0, y=0, body=word)
    draw.draw(baseImage)
    # --------------------------------------------------------------

    # ------------gray----------------------------------------------
    baseImage.colorspace = 'gray'
    # --------------------------------------------------------------

    print(word)
    baseImage.save(filename='./photo_en/'+str(count+1)+'_'+word+'.jpg')
		imagesMatch.append(Image(filename=filename))
	else:
		imagesMatch.append(Image(filename="asciiFont/match127.png"))
imagesNomatch = []
for ascii in range(128):
	filename = "asciiFont/nomatch" + str(ascii) + ".png"
	if os.path.isfile(filename):
		imagesNomatch.append(Image(filename=filename))
	else:
		imagesNomatch.append(Image(filename="asciiFont/nomatch127.png"))

# Prepare a drawing-context.
draw = Drawing()
evilColor = Color("#FF00FF")
extraColor = Color("#FF8000")
draw.stroke_color = evilColor
draw.stroke_width = 4 * scale
draw.fill_opacity = 0

# Draw empty frames around all of the rejected boxes.
for i in range(0,len(rejectedBoxes)):
	boxTop = rejectedBoxes[i]['boxTop']
	boxBottom= rejectedBoxes[i]['boxBottom']
	boxLeft = rejectedBoxes[i]['boxLeft']
	boxRight = rejectedBoxes[i]['boxRight']
	draw.line((boxLeft,boxTop), (boxRight,boxTop))
	draw.line((boxLeft,boxBottom), (boxRight,boxBottom))
	draw.line((boxRight,boxTop), (boxRight,boxBottom))
	draw.line((boxLeft,boxTop), (boxLeft,boxBottom))

# Loop on lines on the selected page.  
Beispiel #23
0
    # ----------gravity---------------------------------------------
    draw.gravity = 'center'
    # --------------------------------------------------------------

    # --------------shadow/border-----------------------------------
    if random.random() < 0.5:
        # shadow
        addx = math.ceil(random.gauss(0, 2))
        addy = math.ceil(random.gauss(0, 2))
        draw.fill_color = Color('black')
        draw.text(x=abs(addx), y=abs(addy), body=word)

    else:
        # border
        draw.stroke_color = Color('rgb('+str(color3[0])+','+str(color3[1])+','+str(color3[2])+')')
        draw.stroke_width = math.ceil(initialPointsize/10)-1
    # --------------------------------------------------------------

    # ----------print word------------------------------------------
    draw.fill_color = Color('rgb('+str(color2[0])+','+str(color2[1])+','+str(color2[2])+')')
    # print('font_color =' + 'rgb('+str(color2[0])+','+str(color2[1])+','+str(color2[2])+')')
    draw.text(x=0, y=0, body=word)
    draw.draw(baseImage)
    # --------------------------------------------------------------

    # ------------gray----------------------------------------------
    baseImage.colorspace = 'gray'
    # --------------------------------------------------------------

    print(word)
Beispiel #24
0
    def draw_box(self, progress_tracker=None):
        if not self.check_paper_layout():
            return None

        tuckbox_dimensions = ['width', 'height', 'depth']
        paper_dimensions = ['width', 'height']
        if ((not all(dimension in self.tuckbox for dimension in tuckbox_dimensions)) or
            (not all(dimension in self.paper for dimension in paper_dimensions))):
            return None

        # How much white space on the sides
        margin_height = (self.paper['height'] - self.pattern_height()) / 2
        margin_width = (self.paper['width'] - self.pattern_width()) / 2

        # Main box draw
        draw = Drawing()
        draw.scale(POINT_PER_MM, POINT_PER_MM)
        draw.stroke_color = Color('black')
        draw.stroke_width = RESOLUTION / (200 * POINT_PER_MM)
        draw.fill_opacity = 0
        draw.translate(margin_width,
                       margin_height + self.lip_size() + self.tuckbox['depth'])
        draw.push()

        # Finger holds draw
        finger_draw = Drawing(draw)
        finger_draw.fill_opacity = 1
        finger_draw.fill_color = Color('white')
        finger_draw.push()

        # Dashed draw
        dashed_draw = Drawing(draw)
        dash_array = [min(self.tuckbox['depth'], self.tuckbox['width'],
                          self.tuckbox['height'])/13] * 2
        dashed_draw.stroke_color = Color('rgb(100,100,100)')
        dashed_draw.fill_opacity = 0
        dashed_draw.stroke_width = RESOLUTION / (300 * POINT_PER_MM)
        dashed_draw.stroke_dash_array = dash_array
        dashed_draw.stroke_dash_offset = 1

        # Folding guides draw
        folding_guides_draw = Drawing()
        folding_guides_draw.scale(POINT_PER_MM, POINT_PER_MM)
        folding_guides_draw.stroke_color = Color('black')
        folding_guides_draw.stroke_width = RESOLUTION / (200 * POINT_PER_MM)

        back_draw = Drawing(draw)
        back_dashed_draw = Drawing(dashed_draw)
        back_folding_guides_draw = Drawing(folding_guides_draw)

        if progress_tracker is not None:
            progress_tracker(5)

        two_openings = 'two_openings' in self.options and self.options['two_openings']
        two_pages = 'two_pages' in self.options and self.options['two_pages']

        dash_array = [min(self.tuckbox['depth'], self.tuckbox['width'],
                          self.tuckbox['height'])/13] * 2

        #
        # Draw the box (or the first page)
        #
        self.draw_front(draw, dashed_draw, two_openings)

        if two_pages:
            offset_left_to_back = self.tuckbox['depth']
        else:
            offset_left_to_back = self.tuckbox['depth']*2 + self.tuckbox['width']

        self.draw_back(offset_left_to_back, back_draw, back_dashed_draw, finger_draw, two_openings)

        if two_pages:
            back_draw.polyline([(self.tuckbox['depth'], 0),
                           (self.tuckbox['depth'] * 0.2, 0),
                           (self.tuckbox['depth'] * 0.2, self.tuckbox['height']),
                           (self.tuckbox['depth'], self.tuckbox['height'])])
            draw.line((self.tuckbox['depth']*2 + self.tuckbox['width'], 0),
                      (self.tuckbox['depth']*2 + self.tuckbox['width'], self.tuckbox['height']))

        if progress_tracker is not None:
            progress_tracker(10)

        # Create the image
        image = Image(width=math.ceil(self.paper['width'] * POINT_PER_MM),
                      height=math.ceil(self.paper['height'] * POINT_PER_MM),
                      background=Color('white'))
        image.resolution = RESOLUTION
        image.unit = 'pixelsperinch'

        if two_pages:
            image2 = Image(width=math.ceil(self.paper['width'] * POINT_PER_MM),
                        height=math.ceil(self.paper['height'] * POINT_PER_MM),
                        background=Color('white'))
            image2.resolution = RESOLUTION
            image2.unit = 'pixelsperinch'
        else:
            image2 = image

        # Draw the faces
        self.draw_faces(image, progress_tracker, with_back = not two_pages)
        if two_pages:
            self.draw_faces(image2, progress_tracker, only_back=True)

        # Draw the lip(s)
        lip = self.draw_lip(top=True)
        if lip is not None:
            image.composite(lip,
                            math.floor((margin_width + self.tuckbox['depth']) * POINT_PER_MM),
                            math.floor((margin_height) * POINT_PER_MM))

        if two_openings:
            lip = self.draw_lip(bottom=True)
            if lip is not None:
                image.composite(lip,
                                math.floor((margin_width + self.tuckbox['depth']) * POINT_PER_MM),
                                math.floor((margin_height + self.tuckbox['depth']*2 + self.lip_size() + self.tuckbox['height']) * POINT_PER_MM))

        if progress_tracker is not None:
            progress_tracker(80)

        # Draw all the lines over
        draw.draw(image)
        back_draw.draw(image2)

        finger_draw.draw(image2)
        self.draw_watermark(image)
        if two_pages:
            self.draw_watermark(image2)

        if progress_tracker is not None:
            progress_tracker(90)

        if "folds_dashed" in self.options and self.options["folds_dashed"]:
            dashed_draw.draw(image)
            back_dashed_draw.draw(image2)

        if "folding_guides" in self.options and self.options["folding_guides"]:
            front_vertical_folds = [margin_width + self.tuckbox['depth'],
                              margin_width +
                              self.tuckbox['depth'] + self.tuckbox['width']]
            if not two_pages:
                front_vertical_folds.extend([margin_width +
                                       self.tuckbox['depth']*2 + self.tuckbox['width'],
                                       margin_width + self.tuckbox['depth']*2 + self.tuckbox['width']*2])

            back_vertical_folds = [margin_width + self.tuckbox['depth'],
                                  margin_width +
                                  self.tuckbox['depth'] + self.tuckbox['width']]

            front_horizontal_folds = [margin_height + self.lip_size(),
                                margin_height + self.lip_size() +
                                self.tuckbox['depth'],
                                margin_height + self.lip_size() +
                                self.tuckbox['depth'] + self.tuckbox['height']]

            if two_openings:
                front_horizontal_folds.append(margin_height + self.lip_size() +
                                        self.tuckbox['depth'] * 2 + self.tuckbox['height'])
                back_horizontal_folds = []
            else:
                back_horizontal_folds = [margin_height + self.lip_size() +
                                        self.tuckbox['depth'] + self.tuckbox['height']]

            self.draw_folds(folding_guides_draw, front_vertical_folds, front_horizontal_folds, margin_height, margin_width)
            self.draw_folds(back_folding_guides_draw, back_vertical_folds, back_horizontal_folds, margin_height, margin_width)

            folding_guides_draw.draw(image)
            back_folding_guides_draw.draw(image2)

        if progress_tracker is not None:
            progress_tracker(100)

        if not two_pages:
            image2 = None

        return image, image2
Beispiel #25
0
    def draw_lip(self, top=False, bottom=False):
        if "back" not in self.faces:
            return None

        if not (top ^ bottom): # 1 and only 1 of top or bottom should be true
            return None

        # First draw a full mask with the lip shape
        lip_full_mask_image = Image(width=math.ceil(self.tuckbox['width'] * POINT_PER_MM),
                                    height=math.ceil(self.lip_size() * POINT_PER_MM))
        lip_full_draw = Drawing()

        lip_full_draw.scale(POINT_PER_MM, POINT_PER_MM)

        # This cannot be too "thin" or the floodfill later would spill over
        lip_full_draw.stroke_width = max(2 / POINT_PER_MM, RESOLUTION / (200 * POINT_PER_MM))

        lip_full_draw.fill_color = Color('white')
        lip_full_draw.color(0, 0, 'reset')
        lip_full_draw.draw(lip_full_mask_image)

        lip_full_draw.stroke_color = Color('black')

        # 1/2 left of lip
        lip_full_draw.bezier([(0, self.lip_size()),
                              (0, self.lip_size() - .75*self.lip_size()),
                              (.2 * self.tuckbox['width'],
                               self.lip_size() - self.lip_size()),
                              (.5 * self.tuckbox['width'], self.lip_size() - self.lip_size())])

        # 1/2 right of lip
        lip_full_draw.bezier([(self.tuckbox['width'], self.lip_size()),
                              (self.tuckbox['width'],
                               self.lip_size() - .75*self.lip_size()),
                              (.8 * self.tuckbox['width'],
                               self.lip_size() - self.lip_size()),
                              (.5 * self.tuckbox['width'], self.lip_size() - self.lip_size())])

        lip_full_draw.draw(lip_full_mask_image)

        lip_full_draw.fill_color = Color('black')
        lip_full_draw.border_color = Color('black')
        lip_full_draw.color(.5 * self.tuckbox['width'],
                            0.8*self.lip_size(), 'filltoborder')

        lip_full_draw.draw(lip_full_mask_image)

        if self.faces['back'][:1] == "#":
            lip_image = Image(width = lip_full_mask_image.width, height = lip_full_mask_image.height,
                            background = Color(self.faces['back']))
        else:
            # Prepare the front image
            angle = 180 if "back_angle" not in self.options else (self.options["back_angle"]+2)*90

            if bottom:
                angle = (angle + 180) % 360

            _, file_extension = os.path.splitext(self.faces['back'])
            tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=file_extension)
            self.resize_rotate_image(self.faces['back'], tmp_file.name, angle, math.ceil(self.tuckbox['width'] * POINT_PER_MM),
                            math.ceil(self.tuckbox['height'] * POINT_PER_MM))
            lip_image = Image(filename=tmp_file.name)
            lip_image.crop(top=lip_image.height - lip_full_mask_image.height)

        # u = image pixel
        # h = height
        # j = row
        # Radius of the hold is {self.tuckbox['width']*.1}
        # if value is 1 (or more_, it's white
        # Top is the tip of the lip, bottom is attached to the box
        # finger_hold_size_save is the row # at which it should be no attenuation below
        finger_hold_size_save = str(
            int(lip_image.height - math.ceil(self.tuckbox['width'] * POINT_PER_MM * 0.1)))
        lip_image = lip_image.fx(
            "j>"+finger_hold_size_save+"?u:1+(u-1)*(j/"+finger_hold_size_save+")")

        lip_image.composite(operator='lighten', image=lip_full_mask_image)

        if bottom:
            lip_image.rotate(180)

        return lip_image
        imagesMatch.append(Image(filename=filename))
    else:
        imagesMatch.append(Image(filename="asciiFont/match127.png"))
imagesNomatch = []
for ascii in range(128):
    filename = "asciiFont/nomatch" + str(ascii) + ".png"
    if os.path.isfile(filename):
        imagesNomatch.append(Image(filename=filename))
    else:
        imagesNomatch.append(Image(filename="asciiFont/nomatch127.png"))

# Prepare a drawing-context.
draw = Drawing()
evilColor = Color("#FF00FF")
extraColor = Color("#FF8000")
draw.stroke_color = evilColor
draw.stroke_width = 4 * scale
draw.fill_opacity = 0

# Draw empty frames around all of the rejected boxes.
for i in range(0, len(rejectedBoxes)):
    boxTop = rejectedBoxes[i]['boxTop']
    boxBottom = rejectedBoxes[i]['boxBottom']
    boxLeft = rejectedBoxes[i]['boxLeft']
    boxRight = rejectedBoxes[i]['boxRight']
    draw.line((boxLeft, boxTop), (boxRight, boxTop))
    draw.line((boxLeft, boxBottom), (boxRight, boxBottom))
    draw.line((boxRight, boxTop), (boxRight, boxBottom))
    draw.line((boxLeft, boxTop), (boxLeft, boxBottom))

# Loop on lines on the selected page.
Beispiel #27
0
from wand.drawing import Drawing
Beispiel #28
0
# Make certain conversions on the background image.
img.type = 'truecolor'
img.alpha_channel = 'activate'

# Determine the range of binsource lines we need to use.  We're guaranteed
# they're all in the binsource lines[] array.
if bankNumber < 4:
	bankNumber = bankNumber ^ 2
startIndex = bankNumber * 4 * 8 * 4 + pageInBank * 4 * 8
endIndex = startIndex + 4 * 8

draw = Drawing()
evilColor = Color("#FF00FF")
extraColor = Color("#FF8000")
draw.stroke_color = evilColor
draw.stroke_width = 4
draw.fill_opacity = 0

# Draw empty frames around all of the rejected boxes.
for i in range(0,len(rejectedBoxes)):
	boxFields = rejectedBoxes[i].split()
	boxLeft = int(boxFields[1])
	boxBottom = backgroundHeight - 1 - int(boxFields[2])
	boxRight = int(boxFields[3])
	boxTop = backgroundHeight - 1 - int(boxFields[4])
	draw.line((boxLeft,boxTop), (boxRight,boxTop))
	draw.line((boxLeft,boxBottom), (boxRight,boxBottom))
	draw.line((boxRight,boxTop), (boxRight,boxBottom))
	draw.line((boxLeft,boxTop), (boxLeft,boxBottom))
Beispiel #29
0
# Make certain conversions on the background image.
img.type = 'truecolor'
img.alpha_channel = 'activate'

# Determine the range of binsource lines we need to use.  We're guaranteed
# they're all in the binsource lines[] array.
if bankNumber < 4:
    bankNumber = bankNumber ^ 2
startIndex = bankNumber * 4 * 8 * 4 + pageInBank * 4 * 8
endIndex = startIndex + 4 * 8

draw = Drawing()
evilColor = Color("#FF00FF")
extraColor = Color("#FF8000")
draw.stroke_color = evilColor
draw.stroke_width = 4
draw.fill_opacity = 0

# Draw empty frames around all of the rejected boxes.
for i in range(0, len(rejectedBoxes)):
    boxFields = rejectedBoxes[i].split()
    boxLeft = int(boxFields[1])
    boxBottom = backgroundHeight - 1 - int(boxFields[2])
    boxRight = int(boxFields[3])
    boxTop = backgroundHeight - 1 - int(boxFields[4])
    draw.line((boxLeft, boxTop), (boxRight, boxTop))
    draw.line((boxLeft, boxBottom), (boxRight, boxBottom))
    draw.line((boxRight, boxTop), (boxRight, boxBottom))
    draw.line((boxLeft, boxTop), (boxLeft, boxBottom))
Beispiel #30
0
    # ----------gravity---------------------------------------------
    draw.gravity = 'center'
    # --------------------------------------------------------------

    # --------------shadow/border-----------------------------------
    if random.random() < 0.5:
        # shadow
        addx = math.ceil(random.gauss(0, 2))
        addy = math.ceil(random.gauss(0, 2))
        draw.fill_color = Color('black')
        draw.text(x=abs(addx), y=abs(addy), body=word)

    else:
        # border
        draw.stroke_color = Color('rgb(' + str(color3[0]) + ',' +
                                  str(color3[1]) + ',' + str(color3[2]) + ')')
        draw.stroke_width = math.ceil(initialPointsize / 10) - 1
    # --------------------------------------------------------------

    # ----------print word------------------------------------------
    draw.fill_color = Color('rgb(' + str(color2[0]) + ',' + str(color2[1]) +
                            ',' + str(color2[2]) + ')')
    # print('font_color =' + 'rgb('+str(color2[0])+','+str(color2[1])+','+str(color2[2])+')')
    draw.text(x=0, y=0, body=word)
    draw.draw(baseImage)
    # --------------------------------------------------------------

    # ------------gray----------------------------------------------
    baseImage.colorspace = 'gray'
    # --------------------------------------------------------------