当前位置: 首页>>代码示例>>Python>>正文


Python Draw.line方法代码示例

本文整理汇总了Python中PIL.ImageDraw.Draw.line方法的典型用法代码示例。如果您正苦于以下问题:Python Draw.line方法的具体用法?Python Draw.line怎么用?Python Draw.line使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PIL.ImageDraw.Draw的用法示例。


在下文中一共展示了Draw.line方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_noise_dots

# 需要导入模块: from PIL.ImageDraw import Draw [as 别名]
# 或者: from PIL.ImageDraw.Draw import line [as 别名]
 def create_noise_dots(image, color, width=3, number=30):
     draw = Draw(image)
     w, h = image.size
     while number:
         x1 = random.randint(0, w)
         y1 = random.randint(0, h)
         draw.line(((x1, y1), (x1 - 1, y1 - 1)), fill=color, width=width)
         number -= 1
     return image
开发者ID:camel007,项目名称:crack-captcha,代码行数:11,代码来源:gen_captcha.py

示例2: noise

# 需要导入模块: from PIL.ImageDraw import Draw [as 别名]
# 或者: from PIL.ImageDraw.Draw import line [as 别名]
 def noise(self, image, number=50, level=2, color=None):
     width, height = image.size
     dx = width / 10
     width -= dx
     dy = height / 10
     height -= dy
     draw = Draw(image)
     for i in xrange(number):
         x = int(random.uniform(dx, width))
         y = int(random.uniform(dy, height))
         draw.line(((x, y), (x + level, y)), fill=color if color else self._color, width=level)
     return image
开发者ID:Chenboxi2015,项目名称:iHome,代码行数:14,代码来源:captcha.py

示例3: drawer

# 需要导入模块: from PIL.ImageDraw import Draw [as 别名]
# 或者: from PIL.ImageDraw.Draw import line [as 别名]
 def drawer(image, text):
     width, height = image.size
     dx = width / 10
     width = width - dx
     dy = height / 10
     height = height - dy
     draw = Draw(image)
     for i in xrange(number):
         x = int(random.uniform(dx, width))
         y = int(random.uniform(dy, height))
         draw.line(((x, y), (x + level, y)), fill=color(), width=level)
     return image
开发者ID:kinorsi,项目名称:Luyasi-Flask,代码行数:14,代码来源:captcha.py

示例4: draw_compiled

# 需要导入模块: from PIL.ImageDraw import Draw [as 别名]
# 或者: from PIL.ImageDraw.Draw import line [as 别名]
def draw_compiled(img, xyc_it, thickness=1):
    """Draws a sequence of x,y,color tuples onto an image.

    xyc_it: iterator of x,y,color tuples. The color of the first entry is
        discarded, all other colors are used as the respective line's color"""
    center_x, center_y = map(lambda n: n / 2, img.size)
    d = Draw(img, "RGBA")
    (x, y), _ = next(xyc_it)
    x, y = x * img.scale + center_x, y * img.scale + center_y
    for ((x2, y2), c) in xyc_it:
        x2, y2 = x2 * img.scale + center_x, y2 * img.scale + center_y
        d.line((x, y, x2, y2), c, width=thickness)
        x, y = x2, y2
开发者ID:perfettiful,项目名称:PiWalkLn,代码行数:15,代码来源:PiWalkLn.py

示例5: generate_capture

# 需要导入模块: from PIL.ImageDraw import Draw [as 别名]
# 或者: from PIL.ImageDraw.Draw import line [as 别名]
def generate_capture(request):
    """
    You can visit the view with GET params like k, b, f to custom the capture.
    b indicates background color, and f foreground color.
    The value of color should be an integer, which will be convert to a hex color value. That is to say the value
     of a color should not be less than 0 or larger than 16777215.
    k indicates the key of the capture. It should exist in session before this view is visited, otherwise A 404 error
    will be throw out.
    And once the view is visited, the answer of the capture will be set a key in session which k indicates.
    """
    keyName, bcolor, fcolor = DEFAULT_CAPTURE_ID, DEFAULT_BACKGROUND, DEFAULT_FOREGROUND
    if 'k' in request.GET:
        if request.GET['k'] in request.session:
            keyName = request.GET['k']
        else:
            raise Http404()
    try:
        if 'b' in request.GET:
            bcolor = '#{:0>6.6s}'.format('%x' % max(min(int(request.GET['b']), 16777215), 0))
        if 'f' in request.GET:
            fcolor = '#{:0>6.6s}'.format('%x' % max(min(int(request.GET['f']), 16777215), 0))
    except:
        raise Http404()
    ver_fun = snippets[randint(0, len(snippets) - 1)]
    x, y = ver_fun[2](), ver_fun[3]()
    request.session[keyName] = '%r' % ver_fun[1](x, y)
    img = Image.new("RGB", (DEFAULT_WIDTH, DEFAULT_HEIGHT), bcolor)
    draw = Draw(img)
    font = ImageFont.truetype('font/SourceCodePro-Regular.ttf', DEFAULT_FONT_SIZE)
    for i in xrange(0, 3):
        draw.line([(0, randint(0, DEFAULT_HEIGHT)), (DEFAULT_WIDTH, randint(1, DEFAULT_HEIGHT))],
                  fill='#{:0>6.6s}'.format('%x' % randint(0, 16777215)))
    if x < 0:
        x = '(%s)' % x
    if y < 0:
        y = '(%s)' % y
    text = ver_fun[0] % (x, y)
    x, y = font.getsize(text)
    draw.text((DEFAULT_WIDTH / 2 - x / 2, DEFAULT_HEIGHT / 2 - y / 2), text, font=font, fill=fcolor)
    response = HttpResponse(mimetype='image/png')
    img.save(response, 'PNG')
    return response
开发者ID:BusyJay,项目名称:Django-Expression-Capture,代码行数:44,代码来源:views.py

示例6: generate_captcha

# 需要导入模块: from PIL.ImageDraw import Draw [as 别名]
# 或者: from PIL.ImageDraw.Draw import line [as 别名]
def generate_captcha(directory="tmp", letters=ascii_uppercase+digits,
        length=3, font_size=30, lines=5, mode="ellipse", font="FreeSerif.ttf"):
    """ Returns a tuple : (path, code) """
    dimensions = ((length + 1) * font_size, int(font_size * 2))
    path = "%s%s" % (os.path.join(directory, "".join(choice(ascii_letters) for
        i in xrange(7))), ".png")
    code = "".join(choice(letters) for i in range(length))
    background_color = tuple( [randrange(190, 230) for i in xrange(3)] )
    master = new_image("RGB", dimensions, background_color)

    # On colle les lettres
    for i, l in enumerate(code):
        img, mask = generate_letter(l, font_size, font)
        for _ in xrange(3):
            # On colle plusieurs fois pour plus de netteté
            master.paste(img, (font_size / 2 + font_size * i , font_size / 3),
                    mask)

    # Et on dessine quelques jolies lignes
    draw = Draw(master)
    for i in xrange(lines):
        color = tuple( [randrange(128, 190) for i in xrange(3)] )
        #pen = Pen("black", opacity=64)
        #pen.color = color
        w = dimensions[0]
        h = dimensions[1]
        geom = (randrange(0, int(w * 3. / 4)), randrange(0, h),
                randrange(int(w * 1. / 4), w), randrange(0, h))
        if mode == "mixed":
            mode_ = choice( ("ellipse", "line") )
        else:
            mode_ = mode
        if mode_ == "ellipse":
            draw.ellipse(geom, None, color)
        else:
            draw.line(geom, color, 1)
    with open(path, "w") as f:
        master.save(f)
    return (path, code)
开发者ID:jeanbon,项目名称:pycoblog,代码行数:41,代码来源:captcha.py

示例7: make_sure_path_exists

# 需要导入模块: from PIL.ImageDraw import Draw [as 别名]
# 或者: from PIL.ImageDraw.Draw import line [as 别名]
overlay_path = output_directory + 'overlay/'

make_sure_path_exists(overlay_path)

# Superimpose smoothed midlines on the (cropped) original image sequence
for i in range(Nf):
    shift = -offsets[i]
#    im = Image.open(original_images.format(i+1))
#    im = im.crop((0, 680, 2260, 680+810)) 
    im = open_png(sillhouette_path.format(i+1))
    im = Image.fromarray(im.astype(np.uint8)).convert('RGB')
    d = Draw(im)
    y = smid[:,i].astype(int)+shift[1]
    x = (np.arange(smid.shape[0])*end[i]/float(smid.shape[0]-1)).astype(int)+shift[0]
    d.line(zip(x,y), fill=(255,0,0), width=3 )
    tp = tip_locations[i]
    d.ellipse((tp[0]-1, tp[1]-1, tp[0]+1, tp[1]+1), fill=(0,0,255))
    im.save(overlay_path+'orig_{}.png'.format(i))


# Calculate scaling between transformed and y-coordinate
# in pixels - dy/di
sc = end / float(smid.shape[0]-1)

# Evaluate derivatives of the smoothed midline - dx/dy and d^2 x / dy^2
# Use scaling factor to give in terms of pixel coordinates
d = u(range(new_mid.shape[0]), range(new_mid.shape[1]), dx=1)/sc
dd = u(range(new_mid.shape[0]), range(new_mid.shape[1]), dx=2)/sc/sc

开发者ID:tuanthng,项目名称:RootAnalysis,代码行数:30,代码来源:optical_flow_analysis_d4.py

示例8: Draw

# 需要导入模块: from PIL.ImageDraw import Draw [as 别名]
# 或者: from PIL.ImageDraw.Draw import line [as 别名]
from PIL import Image
from PIL.ImageDraw import Draw
img = Image.new("RGBA", (100, 100))
draw = Draw(img)
draw.rectangle(((0,0), (100, 100)), fill=(255, 100, 0))
draw.rectangle((50,80,100,200), fill=0)
# img.save("foo.png")
imshow(numpy.asarray(img))

# <codecell>

given_image_size = (600, 900)
image_min_dimen = min(given_image_size)
image_center = (given_image_size[0] / 2, given_image_size[1] / 2)

from PIL import Image
from PIL.ImageDraw import Draw
from math import sin, cos, radians
import random
img = Image.new("RGBA", given_image_size)
draw = Draw(img)
span = 3600
for i in range(0, span):
    deg = float(i) / span * 360
    draw.line((image_center[0], image_center[1], image_center[0] + sin(radians(deg)) * image_min_dimen * 0.4 , image_center[1] + cos(radians(deg)) * image_min_dimen * 0.4), fill=(0, 0, 0), width=2)
imshow(numpy.asarray(img))

# <codecell>


开发者ID:jeroyang,项目名称:microscopy,代码行数:30,代码来源:Untitled0.py


注:本文中的PIL.ImageDraw.Draw.line方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。