本文整理汇总了Python中ImageColor.getrgb方法的典型用法代码示例。如果您正苦于以下问题:Python ImageColor.getrgb方法的具体用法?Python ImageColor.getrgb怎么用?Python ImageColor.getrgb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageColor
的用法示例。
在下文中一共展示了ImageColor.getrgb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_baselines
# 需要导入模块: import ImageColor [as 别名]
# 或者: from ImageColor import getrgb [as 别名]
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
示例2: colorize
# 需要导入模块: import ImageColor [as 别名]
# 或者: from ImageColor import getrgb [as 别名]
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
示例3: make_check_code_image
# 需要导入模块: import ImageColor [as 别名]
# 或者: from ImageColor import getrgb [as 别名]
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()
示例4: init
# 需要导入模块: import ImageColor [as 别名]
# 或者: from ImageColor import getrgb [as 别名]
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
示例5: create_cluster_colors_rgb
# 需要导入模块: import ImageColor [as 别名]
# 或者: from ImageColor import getrgb [as 别名]
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
示例6: general_filling_rec
# 需要导入模块: import ImageColor [as 别名]
# 或者: from ImageColor import getrgb [as 别名]
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)
示例7: writeProgressImage
# 需要导入模块: import ImageColor [as 别名]
# 或者: from ImageColor import getrgb [as 别名]
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)
示例8: drawSkin
# 需要导入模块: import ImageColor [as 别名]
# 或者: from ImageColor import getrgb [as 别名]
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)
示例9: crop
# 需要导入模块: import ImageColor [as 别名]
# 或者: from ImageColor import getrgb [as 别名]
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")
示例10: display_distance_LUT
# 需要导入模块: import ImageColor [as 别名]
# 或者: from ImageColor import getrgb [as 别名]
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
示例11: color_bg
# 需要导入模块: import ImageColor [as 别名]
# 或者: from ImageColor import getrgb [as 别名]
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
示例12: __init__
# 需要导入模块: import ImageColor [as 别名]
# 或者: from ImageColor import getrgb [as 别名]
def __init__(self, fontname, textcol_bright, textcol_dark, textsize=40, noiselines=False, bgpicture=None, squiggly=False):
self.font=ImageFont.truetype(fontname, textsize)
self.lettersize=self.font.getsize('x')
if type(textcol_bright)!=tuple:
textcol_bright=ImageColor.getrgb(textcol_bright)
if type(textcol_dark)!=tuple:
textcol_dark=ImageColor.getrgb(textcol_dark)
self.textcol_bright=textcol_bright
self.textcol_dark=textcol_dark
ar,ag,ab=self.textcol_bright
self.textcol_avg=(ar+self.textcol_dark[0])/2, (ag+self.textcol_dark[1])/2, (ab+self.textcol_dark[2])/2
self.noiselines=noiselines
self.squiggly=squiggly
if bgpicture:
self.bgpicture=Image.open(bgpicture)
else:
self.bgpicture=None
示例13: double_ended
# 需要导入模块: import ImageColor [as 别名]
# 或者: from ImageColor import getrgb [as 别名]
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)
示例14: build_tree
# 需要导入模块: import ImageColor [as 别名]
# 或者: from ImageColor import getrgb [as 别名]
def build_tree():
tree = Quad(Rect(0, 0, size, size))
level = Level(Rect(0, 0, size, size))
level.color = ImageColor.getcolor('grey', mode)
tree.charge(level)
room = Room(Rect(4, 4, 16, 16), level, name='room')
room.color = ImageColor.getcolor('orange', mode)
tree.charge(room)
table = Furniture(Rect(0, 0, 4, 3), room, name='table')
table.color = ImageColor.getcolor('brown', mode)
lamp = Furniture(Rect(1, 1, 1, 1), table, name='lamp')
lamp.color = ImageColor.getcolor('yellow', mode)
tree.charge(table)
bed = Bed(Rect(4, 0, 4, 8), room, color=ImageColor.getrgb('white'),
decor_color=ImageColor.getrgb('darkcyan'))
tree.charge(bed)
bed2 = Bed(Rect(9, 0, 4, 8), room, color=ImageColor.getrgb('white'),
decor_color=ImageColor.getrgb('crimson'))
tree.charge(bed2)
bed2.tear_down()
#bed = Furniture(Rect(4, 0, 4, 8), room, name='bed')
#bed.color = ImageColor.getcolor('green', mode)
#tree.charge(bed)
#pillow = Furniture(Rect(1, 1, 2, 1), bed, name='pillow')
#pillow.color = ImageColor.getcolor('white', mode)
#tree.charge(pillow)
#sheet = Furniture(Rect(0, 3, 4, 5), bed, name='sheet')
#sheet.color = ImageColor.getcolor('white', mode)
#tree.charge(sheet)
lump = Block(Rect(32, 32, 8, 8), room, name='lump', abs=True)
lump.color = ImageColor.getcolor('black', mode)
tree.charge(lump)
return tree
示例15: create_cluster_colors
# 需要导入模块: import ImageColor [as 别名]
# 或者: from ImageColor import getrgb [as 别名]
def create_cluster_colors(n):
# 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
colors.append(ImageColor.getrgb("hsl(%d,%d%%,%d%%)" % (h,s,l)) )
return colors