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


Python ImageColor类代码示例

本文整理汇总了Python中ImageColor的典型用法代码示例。如果您正苦于以下问题:Python ImageColor类的具体用法?Python ImageColor怎么用?Python ImageColor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: draw_baselines

    def draw_baselines(self, img_in):
        img_out = img_in.copy()
        draw = ImageDraw.Draw(img_out)
    
        prev_floor = 0
        w, h = img_out.size
    
        gap_color = ImageColor.getrgb('#ccccFF')
    
        lines = scrape.calc_lines(scrape.font_metrics(), 7)

        for i, (ceiling, base, floor) in enumerate(lines):

            # draw the baseline
            color = ImageColor.getrgb("#ffdddd")
            if not base:
                base = floor -2
                color = ImageColor.getrgb("red")
    
            draw.line([(0, base), (w, base)], fill=color)
            
            # shade gap between the lines
            draw.rectangle((0, prev_floor, w, ceiling), fill=gap_color)
            prev_floor = floor +1
                
        # shade final gap:
        draw.rectangle((0, prev_floor, w, h), fill=gap_color)
    
        # now draw the text back over the baselines:
        img_out = ImageChops.darker(img_in, img_out)

        # uncomment to zoom in for debugging
        # img_out = img_out.resize((w *2 , h* 2))

        return img_out
开发者ID:mehulsbhatt,项目名称:snakeeyes,代码行数:35,代码来源:Region.py

示例2: colorize

def colorize(data, colormap):
    #data = np.zeros((256, 256), dtype=np.float32)
    #data.data = raw.data
    out = np.zeros((256, 256, 4), dtype=np.uint8)
    tmp = np.zeros((256, 256), dtype=np.uint32)
    tmp.data = out.data
    
    c = np.zeros(4, dtype=np.uint8)
    d = np.zeros(1, dtype=np.uint32)
    d.data = c.data
    
    if colormap['missing']: c[0:3] = ImageColor.getrgb(colormap['missing'])
    else: c[0:3] = 0
    c[3] = 255
    tmp[...] = d
    
    n = 0
    for b in colormap['bounds']:
        step = 1.0*(b['end'] - b['start'])/b['steps']
        for i in range(b['steps']):
            low = b['start'] + i*step
            high = low + step
            mask = np.logical_and(data > low, data < high)
            c[0:3] = ImageColor.getrgb(colormap['colors'][n + i])
            tmp[mask] = d
        n += b['steps']
    
    return out
开发者ID:peterkuma,项目名称:ccbrowse,代码行数:28,代码来源:utils.py

示例3: make_check_code_image

    def make_check_code_image(self, image=''):

        color = ImageColor.getrgb('white')
        #im = Image.open(image)
        im = Image.new('RGB',(60,20), color) 
        draw = ImageDraw.Draw(im) 
        
        mp = md5.new() 
        mp_src = mp.update(str(datetime.datetime.now())) 
        mp_src = mp.hexdigest()

        rand_str = mp_src[0:4] 
        #print rand_str
        color = ImageColor.getrgb('LightGray')
        for i in range(200):
            x = random.randrange(1,60)
            y = random.randrange(1,20)
            draw.point((x, y), fill=color)
        
        draw.text((5, 1), rand_str[0], fill = self.get_color(), font = self.get_font())
        draw.text((15, 1), rand_str[1], fill = self.get_color(), font = self.get_font())
        draw.text((30, 1), rand_str[2], fill = self.get_color(), font = self.get_font())
        draw.text((45, 1), rand_str[3], fill = self.get_color(), font = self.get_font())
        
        draw.line((0, 10, 60, 15), fill = self.get_color())
        
        del draw 
        session['checkcode'] = rand_str 
        buf = StringIO.StringIO()   
        im.save(buf, 'gif')
        buf.closed
        if image: 
            im.save(image) 
        return buf.getvalue()
开发者ID:dalinhuang,项目名称:portable,代码行数:34,代码来源:checkcode.py

示例4: init

	def init(self, color=ImageColor.getrgb('white'),
			 decor_color=ImageColor.getrgb('blue')):
		self.color = color

		self.pillow = Decor(Rect(1, 1, 2, 1), self, 'pillow')
		self.pillow.color = decor_color

		self.sheet = Decor(Rect(0, 3, 4, 5), self, 'sheet')
		self.sheet.color = decor_color
开发者ID:PatrickKennedy,项目名称:levelgenerator,代码行数:9,代码来源:blocks.py

示例5: genImage

    def genImage(self):
        """Create a PNG from the contents of this flowable.

        Required so we can put inline math in paragraphs.
        Returns the file name.
        The file is caller's responsability.

        """

        dpi = 72
        scale = 10

        try:
            import Image
            import ImageFont
            import ImageDraw
            import ImageColor
        except ImportError:
            from PIL import (
                Image,
                ImageFont,
                ImageDraw,
                ImageColor,
            )

        if not HAS_MATPLOTLIB:
            img = Image.new('L', (120, 120), ImageColor.getcolor("black", "L"))
        else:
            width, height, descent, glyphs,\
            rects, used_characters = self.parser.parse(
                enclose(self.s), dpi)
            img = Image.new('L', (int(width*scale), int(height*scale)),
                ImageColor.getcolor("white", "L"))
            draw = ImageDraw.Draw(img)
            for ox, oy, fontname, fontsize, num, symbol_name in glyphs:
                font = ImageFont.truetype(fontname, int(fontsize*scale))
                tw, th = draw.textsize(unichr(num), font=font)
                # No, I don't understand why that 4 is there.
                # As we used to say in the pure math
                # department, that was a numerical solution.
                draw.text((ox*scale, (height - oy - fontsize + 4)*scale),
                           unichr(num), font=font)
            for ox, oy, w, h in rects:
                x1 = ox*scale
                x2 = x1 + w*scale
                y1 = (height - oy)*scale
                y2 = y1 + h*scale
                draw.rectangle([x1, y1, x2, y2],
                               fill=ImageColor.getcolor("black", "L"))

        fh, fn = tempfile.mkstemp(suffix=".png")
        os.close(fh)
        img.save(fn)
        return fn
开发者ID:ddd332,项目名称:presto,代码行数:54,代码来源:math_flowable.py

示例6: general_filling_rec

def general_filling_rec(fillcolor, bordercolor, maxX, maxY, draw, pic, x, y):
    sys.setrecursionlimit(100000)
    fc = ImageColor.getrgb(fillcolor)
    bc = ImageColor.getrgb(bordercolor)

    def GFill(x, y):
        if 0 < x < maxX and 0 < y < maxY:
            color = pic.getpixel((x, y))
            if color != bc and color != fc:
                draw.point([x, y], fc)
                GFill(x + 1, y)
                GFill(x, y + 1)
                GFill(x - 1, y)
                GFill(x, y - 1)
开发者ID:k1-hedayati,项目名称:oldprojects,代码行数:14,代码来源:general_filling.py

示例7: create_cluster_colors_rgb

def create_cluster_colors_rgb(n, normalize=True):
    # create n distinct colors in rgb format

    colors = []
    for i in range(n):
        h = int( float(i) / float(n) *  360.0 )
        s = 50
        l = 50
        if normalize:
            colors.append(np.array(ImageColor.getrgb("hsl(%d,%d%%,%d%%)" % (h,s,l))) / 255.0 )
        else:
            colors.append(np.array(ImageColor.getrgb("hsl(%d,%d%%,%d%%)" % (h,s,l))))

    return colors
开发者ID:bionicv,项目名称:utils,代码行数:14,代码来源:utils.py

示例8: writeProgressImage

def writeProgressImage(value, range, file, text=None, warnThreshold=0.8) :

  import PIL
  import Image, ImageDraw, ImageColor, ImageFont

  WIDTH = 100
  HEIGHT = 18

  def centerTextInBox(font, text, size) :
    center = [0,0]
    center[0] = size[0]/2.0 - font.getsize(text)[0]/2.0
    center[1] = size[1]/2.0 - font.getsize(text)[1]/2.0 + 1
    return center

  im = Image.new("RGBA",(WIDTH, HEIGHT))

  outline = ImageColor.getrgb("#000000")
  background = ImageColor.getrgb("#4697ff")
  bar = ImageColor.getrgb("#14ff00")
  barWarn = ImageColor.getrgb("#ff0f00")
  textColour = ImageColor.getrgb("#000000")

  try :
    percentage = float(value)/range
  except :
    percentage = 0.0

  if percentage > warnThreshold :
    barColour = barWarn
  else :
    barColour = bar
  barWidth = percentage * im.size[0]
  barWidth = min(barWidth, im.size[0])

  draw = ImageDraw.Draw(im)
  draw.rectangle([0,0, im.size[0]-1, im.size[1]-1], outline=outline, fill=background)
  draw.rectangle([0,0, barWidth-1, im.size[1]-1], outline=outline, fill=barColour)

  font = ImageFont.load_default()
  try :
    font = ImageFont.truetype("/var/tmp/Nimbus Sans L,",16)
  except :
    debugOutput("Cannot load Nimbus font")
    font = ImageFont.load_default()
  if text :
    draw.text(centerTextInBox(font, text, im.size), text, font=font, fill=textColour)

  if not drool.settings.options.testRun : 
    im.save(file)
开发者ID:blundeln,项目名称:drool,代码行数:49,代码来源:core.py

示例9: drawSkin

def drawSkin(imagePath, size, outlineColour, bgColour) :
  import PIL
  import Image, ImageDraw, ImageColor, ImageFont
  
  borderWidth = 2
  
  im = Image.new("RGBA",(size[0], size[1]))

  outline = ImageColor.getrgb(outlineColour)
  background = ImageColor.getrgb(bgColour)

  draw = ImageDraw.Draw(im)
  draw.rectangle([0,0, im.size[0]-1, im.size[1]-1], outline=outline, fill=background)

  im.save(imagePath)
开发者ID:blundeln,项目名称:drool,代码行数:15,代码来源:test.py

示例10: display_distance_LUT

    def display_distance_LUT(self, dlut, sname):
        display_im = self.im.copy()
        draw = ImageDraw.Draw(display_im)

        print 'Grid w x h =', self.grid_width, self.grid_height
        max_d = 0

        for gx in range(self.grid_width-1):
            for gy in range(self.grid_height-1):
                (x,y) = self.grid_to_map((gx,gy))
                if (gx,gy) in self.occupied:
                    continue
                min_d = 40.0
                for ga in range(self.num_angles-1):
                    #print 
                    d = dlut.distance(x,y,self.discrete_angle_to_map_angle(ga))
                    #d2 = self.distance_to_obstacle((gx,gy),self.discrete_angle_to_map_angle(ga))
                    #print 'Checking <', gx, gy, ga, '> d = ', d, 'd2=',d2
                    if d < min_d:
                        min_d = d
                #print (x,y), '->', min_d
                if min_d > max_d:
                    max_d = min_d
                rvalue = int(255 - (min_d*255/5.0))
                if rvalue < 0:
                    rvalue = 0
                self.draw_grid_rectangle(gx,gy,draw,ImageColor.getrgb('rgb(' + str(rvalue) + ',0,0)'))
        print 'MAX D= ', max_d
                   
        #Save the image
        display_im.save(sname)
        del draw
        del display_im                   
开发者ID:aes421,项目名称:Maze-Solving-Robot,代码行数:33,代码来源:discretemap.py

示例11: crop

def crop(image_file, bgcolor=ImageColor.getrgb("white")):
  image = Image.open(image_file,'r')
  mask = Image.new("RGB", image.size, bgcolor)
  diff = ImageChops.difference(image, mask)
  bbox = diff.getbbox()
  new_image = image.crop(bbox)
  new_image.save(image_file,"png")
开发者ID:vadimgu,项目名称:restedblogger,代码行数:7,代码来源:lilypond_directive.py

示例12: color_bg

def color_bg(request, color, opacity=100):
    """
    Generates a 10x10 square image in the color requested.
    Useful for generating background colors based on user-provided 
    color settings.
    """
    import Image, ImageDraw, ImageColor

    alpha = int((int(opacity) / 100.0) * 255)

    if len(color) != 3 and len(color) != 6:
        raise Http404
    color = "#%s" % color
    color = ImageColor.getrgb(color) + (alpha,)

    size = (10, 10)

    etag = md5_constructor("%s%s" % (color, size)).hexdigest()
    if request.META.get("HTTP_IF_NONE_MATCH") == etag:
        return HttpResponseNotModified()

    img = Image.new("RGBA", size=size, color=color)

    response = HttpResponse(mimetype="image/png")
    img.save(response, "PNG")
    response["Etag"] = etag
    return response
开发者ID:joaquinquintas,项目名称:trade,代码行数:27,代码来源:views.py

示例13: setink

 def setink(self, ink):
     # compatibility
     if Image.isStringType(ink):
         ink = ImageColor.getcolor(ink, self.mode)
     if self.palette and not Image.isNumberType(ink):
         ink = self.palette.getcolor(ink)
     self.ink = self.draw.draw_ink(ink, self.mode)
开发者ID:nh,项目名称:imgc,代码行数:7,代码来源:ImageDraw.py

示例14: brightness

def brightness(image, amount=50):
    """Adjust brightness from black to white
    - amount: -1(black) 0 (unchanged) 1(white)
    - repeat: how many times it should be repeated"""
    if amount == 0:
        return image

    image = imtools.convert_safe_mode(image)

    if amount < 0:
        #fade to black
        im = imtools.blend(
                image,
                Image.new(image.mode, image.size, 0),
                -amount / 100.0)
    else:
        #fade to white
        im = imtools.blend(
                image,
                Image.new(image.mode, image.size,
                    ImageColor.getcolor('white', image.mode)),
                amount / 100.0)
    #fix image transparency mask
    if imtools.has_alpha(image):
        im.putalpha(imtools.get_alpha(image))
    return im
开发者ID:CamelliaDPG,项目名称:Camellia,代码行数:26,代码来源:brightness.py

示例15: double_ended

    def double_ended(low, zero, high, *args, **kwargs):
        '''double_ended(low, zero, high) -> ColorMap

        low, zero, high should be scalar. 

        Returns a ColorMap that is grey at zero and increases in saturation
        toward low and high.'''

        lowcolor = ImageColor.getrgb("hsl(180,100%,50%)")
        highcolor = ImageColor.getrgb("hsl(0,100%,50%)")
        zerocolor = ImageColor.getrgb("hsl(0,100%,0%)")

        points = np.asarray([ (low,) + lowcolor,
            (zero,) + zerocolor,
            (high,) + highcolor ])

        return ColorMap(points)
开发者ID:damonwang,项目名称:scivis-proj4,代码行数:17,代码来源:cm.py


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