代码拉取完成,页面将自动刷新
#!/usr/bin/env python
#!coding=utf-8
import Image
import os, sys
sys.setrecursionlimit(1000000) #这里把递归次数设置为一百万
common_colors = [
0xFFB6C1FF,
0xFFC0CBFF,
0xFFF0F5FF,
0xDB7093FF,
0xFF69B4FF,
0xFF1493FF,
0xC71585FF,
0xDA70D6FF,
0xD8BFD8FF,
0xDDA0DDFF,
0xEE82EEFF,
0xFF00FFFF,
0x8B008BFF,
0x800080FF,
0xBA55D3FF,
0x9400D3FF,
0x9932CCFF,
0x8A2BE2FF,
0x9370DBFF,
0x7B68EEFF,
0x6A5ACDFF,
0x483D8BFF,
0xE6E6FAFF,
0xF8F8FFFF,
0x0000FFFF,
0x0000CDFF,
0x191970FF,
0x00008BFF,
0x000080FF,
0x6495EDFF,
0xB0C4DEFF,
0x778899FF,
0x708090FF,
0x1E90FFFF,
0xF0F8FFFF,
0x87CEFAFF,
0x87CEEBFF,
0x00BFFFFF,
0xADD8E6FF,
0xB0E0E6FF,
0x5F9EA0FF,
0xF0FFFFFF,
0xE0FFFFFF,
0xAFEEEEFF,
0x00FFFFFF,
0x00FFFFFF,
0x00CED1FF,
0x2F4F4FFF,
0x008B8BFF,
0x008080FF,
0x48D1CCFF,
0x20B2AAFF,
0x40E0D0FF,
0x7FFFD4FF,
0x66CDAAFF,
0x00FA9AFF,
0xF5FFFAFF,
0x00FF7FFF,
0x3CB371FF,
0x2E8B57FF,
0xF0FFF0FF,
0x90EE90FF,
0x98FB98FF,
0x8FBC8FFF,
0x32CD32FF,
0x00FF00FF,
0x228B22FF,
0x008000FF,
0x006400FF,
0x7CFC00FF,
0xADFF2FFF,
0x556B2FFF,
0x9ACD32FF,
0x6B8E23FF,
0xF5F5DCFF,
0xFAFAD2FF,
0xFFFFF0FF,
0xFFFFE0FF,
0xFFFF00FF,
0x808000FF,
0xBDB76BFF,
0xFFFACDFF,
0xEEE8AAFF,
0xF0E68CFF,
0xFFD700FF,
0xFFF8DCFF,
0xDAA520FF,
0xB8860BFF,
0xFFFAF0FF,
0xFDF5E6FF,
0xF5DEB3FF,
0xFFE4B5FF,
0xFFA500FF,
0xFFEFD5FF,
0xFFEBCDFF,
0xFFDEADFF,
0xFAEBD7FF,
0xD2B48CFF,
0xDEB887FF,
0xFFE4C4FF,
0xFF8C00FF,
0xFAF0E6FF,
0xCD853FFF,
0xFFDAB9FF,
0xF4A460FF,
0xD2691EFF,
0x8B4513FF,
0xFFF5EEFF,
0xA0522DFF
]
#递归调用处理图片,将一个连续的区域进行着色
def fill(img, point, origcolor, fillcolor):
x = point[0];
y = point[1];
if (img.getpixel((x, y)) == origcolor): #如果是原始色,才需要进行递归,否则结束
img.putpixel((x, y), fillcolor);
if (x-1 >= 0):
fill(img, (x-1, y), origcolor, fillcolor)
if (y-1 >= 0):
fill(img, (x, y-1), origcolor, fillcolor)
if (x+1 < img.size[0]):
fill(img, (x+1, y), origcolor, fillcolor)
if (y+1 < img.size[1]):
fill(img, (x, y+1), origcolor, fillcolor)
pass;
def value2color(v):
return (v/(256*256*256), v/(256*256) % 256, v/(256) % 256, v % 256)
if __name__ == '__main__':
print "正在打开 %s ..." % sys.argv[1]
img = Image.open(sys.argv[1])
origcolor = (143, 208, 240, 255)
color_no = 0;
fillcolorvalue = common_colors[color_no]
print img.format, img.size, img.mode
for i in xrange(img.size[0]):
for j in xrange(img.size[1]):
if img.getpixel((i, j)) == origcolor: #探测到原始色
fill (img, (i,j), origcolor, value2color(fillcolorvalue))
color_no += 1;
fillcolorvalue = common_colors[color_no]
print "color change to %d" % color_no
print "正在保存 %s ..." % sys.argv[2]
img.save(sys.argv[2])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。