- Joined
- Feb 23, 2019
Python:
from PIL import Image
filename = "asd.png"
b_per = 4
desired_width = 100 // b_per
try:
im = Image.open(filename)
except:
print("Error.\nDid you put the correct extension?")
else:
width, height = im.size
if width != desired_width:
# bullshit code c:
raise KeyError(f"Your width needs to be {desired_width}px, but it is {width}px.")
try:
r, g, b, a = im.getpixel((0, 0))
rgba = True
except:
rgba = False
with open("result_table.txt", "w", encoding="utf-8") as file:
file.write("[table]")
# what-fucking ever
if rgba:
for h in range(height):
file.write("[tr]")
for w in range(width):
r, g, b, a = im.getpixel((w, h))
pixel = r + g + b
if pixel < 300:
file.write(f"[th width=\"{b_per}%\"]\n[/th]")
else:
file.write(f"[td width=\"{b_per}%\"]\n[/td]")
file.write("[/tr]")
else:
for h in range(height):
file.write("[tr]")
for w in range(width):
r, g, b = im.getpixel((w, h))
pixel = r + g + b
if pixel < 300:
file.write(f"[th width=\"{b_per}%\"]\n[/th]")
else:
file.write(f"[td width=\"{b_per}%\"]\n[/td]")
file.write("[/tr]")
file.write("[/table]")