MAX = 25 pic = Image.new("RGB",(MAX,MAX)) str ='''0000000001110010000000000000000000001111010000000000000000011100010000000000000000010111100000000000000000001010101000000000000000000011000101000000000000000010101010100000000000000000100000110000000011000111011101101000110000001000010110010010010100010011110100001110111001100111101001010110010010011000001001100001001101000111100011111101110010100010110111110011011111101111000110110010010101101100100011110011111111111011100000000101100011000101000000000010010100101010001000000001010101010001100100000000001001111111100100000000000011001011110111000000000100110010010000100000000110000110110110010000000011010000101110101''' i=0 for y inrange(0,MAX): for x inrange(0,MAX): if(str[i] == '1'): pic.putpixel([x,y],(0,0,0)) else:pic.putpixel([x,y],(255,255,255)) i = i+1 pic.show() pic.save("flag.png")
# from PIL import Image # # img = Image.open('D:\\new\\cat.png') # width, height = img.size # pixs_list = [] # for w in range(5, width, 11): # for h in range(5, height, 11): # pix = img.getpixel((w, h)) # pixs_list.append(pix) # #分解下pixs_list的长度,就可以得到生成图片的宽高 # new_width, new_height = 215, 215 # new_img = Image.new('RGB', (new_width, new_height)) # idx = 0 # for n_w in range(new_width): # for n_h in range(new_height): # new_img.putpixel((n_w, n_h), pixs_list[idx]) # idx += 1 # new_img.save('ok.png') # new_img.show() # from PIL import Image # # img = Image.open('ok.png') # width, height = img.size # pixs_list = [] # for w in range(2, width, 5): # for h in range(2, height, 5): # pix = img.getpixel((w, h)) # pixs_list.append(pix) # #分解pixs_list的长度, # new_width, new_height = 43, 43 # new_img = Image.new('RGB', (new_width, new_height)) # idx = 0 # for n_w in range(new_width): # for n_h in range(new_height): # new_img.putpixel((n_w, n_h), pixs_list[idx]) # idx += 1 # new_img.save('ok1.png') # new_img.show()
from PIL import Image
img = Image.open('ok1.png') if img.mode == "P": img = img.convert("RGB") assert img.size[0] == img.size[1] dim = width, height = img.size
st = 1 a = 9 b = 39 for _ inrange(st): with Image.new(img.mode, dim) as canvas: for nx inrange(img.size[0]): for ny inrange(img.size[0]): y = (ny - nx * a) % width x = (nx - y * b) % height canvas.putpixel((y, x), img.getpixel((ny, nx))) canvas.show() canvas.save('ok2.png')