Natsukl

image2text2x4color

Aug 18th, 2023 (edited)
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.70 KB | Software | 0 0
  1. from PIL import Image
  2. img = Image.open("your_image.png")
  3. width, height = img.size
  4. img = img.convert("RGB")
  5. img = img.load()
  6. def rgb2hex(r,g,b):
  7.     return '{:02x}{:02x}{:02x}'.format(r, g, b)
  8. def colordif(r1,g1,b1,r2,g2,b2):
  9.     return abs(r1-r2)+abs(g1-g2)+abs(b1-b2)
  10. characters = [' ', '๐œบจ', '๐œบซ', '๐Ÿฎ‚', '๐œด€', 'โ–˜', '๐œด', '๐œด‚', '๐œดƒ', '๐œด„', 'โ–', '๐œด…', '๐œด†', '๐œด‡', '๐œดˆ', 'โ–€', '๐œด‰', '๐œดŠ', '๐œด‹', '๐œดŒ', '๐Ÿฏฆ', '๐œด', '๐œดŽ', '๐œด', '๐œด', '๐œด‘', '๐œด’', '๐œด“', '๐œด”', '๐œด•', '๐œด–', '๐œด—', '๐œด˜', '๐œด™', '๐œดš', '๐œด›', '๐œดœ', '๐œด', '๐œท‘', '๐œดŸ', '๐Ÿฏง', '๐œด ', '๐œดก', '๐œดข', '๐œดฃ', '๐œดค', '๐œดฅ', '๐œดฆ', '๐œดง', '๐œดจ', '๐œดฉ', '๐œดช', '๐œดซ', '๐œดฌ', '๐œดญ', '๐œดฎ', '๐œดฏ', '๐œดฐ', '๐œดฑ', '๐œดฒ', '๐œดณ', '๐œดด', '๐œดต', '๐Ÿฎ…', '๐œบฃ', '๐œดถ', '๐œดท', '๐œดธ', '๐œดน', '๐œดบ', '๐œดป', '๐œดผ', '๐œดฝ', '๐œดพ', '๐œดฟ', '๐œต€', '๐œต', '๐œต‚', '๐œตƒ', '๐œต„', 'โ––', '๐œต…', '๐œต†', '๐œต‡', '๐œตˆ', 'โ–Œ', '๐œต‰', '๐œตŠ', '๐œต‹', '๐œตŒ', 'โ–ž', '๐œต', '๐œตŽ', '๐œต', '๐œต', 'โ–›', '๐œต‘', '๐œต’', '๐œต“', '๐œต”', '๐œต•', '๐œต–', '๐œต—', '๐œต˜', '๐œต™', '๐œตš', '๐œต›', '๐œตœ', '๐œต', '๐œตž', '๐œตŸ', '๐œต ', '๐œตก', '๐œตข', '๐œตฃ', '๐œตค', '๐œตฅ', '๐œตฆ', '๐œตง', '๐œตจ', '๐œตฉ', '๐œตช', '๐œตซ', '๐œตฌ', '๐œตญ', '๐œตฎ', '๐œตฏ', '๐œตฐ', '๐œบ ', '๐œตฑ', '๐œตฒ', '๐œตณ', '๐œตด', '๐œตต', '๐œตถ', '๐œตท', '๐œตธ', '๐œตน', '๐œตบ', '๐œตป', '๐œตผ', '๐œตฝ', '๐œตพ', '๐œตฟ', '๐œถ€', '๐œถ', '๐œถ‚', '๐œถƒ', '๐œถ„', '๐œถ…', '๐œถ†', '๐œถ‡', '๐œถˆ', '๐œถ‰', '๐œถŠ', '๐œถ‹', '๐œถŒ', '๐œถ', '๐œถŽ', '๐œถ', 'โ–—', '๐œถ', '๐œถ‘', '๐œถ’', '๐œถ“', 'โ–š', '๐œถ”', '๐œถ•', '๐œถ–', '๐œถ—', 'โ–', '๐œถ˜', '๐œถ™', '๐œถš', '๐œถ›', 'โ–œ', '๐œถœ', '๐œถ', '๐œถž', '๐œถŸ', '๐œถ ', '๐œถก', '๐œถข', '๐œถฃ', '๐œถค', '๐œถฅ', '๐œถฆ', '๐œถง', '๐œถจ', '๐œถฉ', '๐œถช', '๐œถซ', 'โ–‚', '๐œถฌ', '๐œถญ', '๐œถฎ', '๐œถฏ', '๐œถฐ', '๐œถฑ', '๐œถฒ', '๐œถณ', '๐œถด', '๐œถต', '๐œถถ', '๐œถท', '๐œถธ', '๐œถน', '๐œถบ', '๐œถป', '๐œถผ', '๐œถฝ', '๐œถพ', '๐œถฟ', '๐œท€', '๐œท', '๐œท‚', '๐œทƒ', '๐œท„', '๐œท…', '๐œท†', '๐œท‡', '๐œทˆ', '๐œท‰', '๐œทŠ', '๐œท‹', '๐œทŒ', '๐œท', '๐œทŽ', '๐œท', '๐œท', '๐œท‘', '๐œท’', '๐œท“', '๐œท”', '๐œท•', '๐œท–', '๐œท—', '๐œท˜', '๐œท™', '๐œทš', 'โ–„', '๐œท›', '๐œทœ', '๐œท', '๐œทž', 'โ–™', '๐œทŸ', '๐œท ', '๐œทก', '๐œทข', 'โ–Ÿ', '๐œทฃ', 'โ–†', '๐œทค', '๐œทฅ', 'โ–ˆ', ]
  11. for y in range(round(height/4-0.5)):
  12.     row = ""
  13.     for x in range(round(width/2-0.5)):
  14.         bit = 0
  15.         colors = []
  16.         colorshex = []
  17.         nocolor = []
  18.         for i in range(8):
  19.             r,g,b = img[x*2+(i%2),y*4+round(i/2-0.1)]
  20.             hex2test = [rgb2hex(r, g, b)]
  21.             if hex2test[0] in colorshex:
  22.                 nocolor[hex2test in colorshex] += 1
  23.             else:
  24.                 colors += img[x*2+(i%2), y*4+round(i/2-0.1)]
  25.                 colorshex += hex2test
  26.                 nocolor += [0]
  27.         Max = nocolor.index(max(nocolor))*3
  28.         color1 = colors[Max:Max+3]
  29.         nocolor = 0
  30.         color2 = [0,0,0]
  31.         for i in range(0,len(colors),3):
  32.             r1,g1,b1 = color1
  33.             r2,g2,b2 = colors[i:i+3]
  34.             if colordif(r1,g1,b1,r2,g2,b2) > nocolor:
  35.                 nocolor = colordif(r1,g1,b1,r2,g2,b2)
  36.                 color2 = colors[i:i+3]
  37.         for i in range(8):
  38.             r1,g1,b1 = img[x*2+(i%2),y*4+round(i/2-0.1)]
  39.             r2,g2,b2 = color1
  40.             nocolor = colordif(r1,g1,b1,r2,g2,b2)
  41.             r2,g2,b2 = color2
  42.             bit += (nocolor>colordif(r1,g1,b1,r2,g2,b2))*(2**i)
  43.         r,g,b = color1
  44.         color1 = rgb2hex(r,g,b)
  45.         r,g,b = color2
  46.         color2 = rgb2hex(r,g,b)
  47.         row += "b"+color1+"F"+color2+characters[bit]
  48.     print(row)
  49. print('image converter made by Scar32 $u"https://pastebin.com/u/Natsukl"@')
  50.  
Tags: text
Advertisement
Add Comment
Please, Sign In to add comment