gabu
@gabu
████████████████████████████████████████
████████████████████████████████████████
████████████████████████████████████████
████████████████████████████████████████
████████████████████████████████████████
████████████████████████████████████████████
████████████████████████████████████████████████
████████████████████████████████████████████████████
████████████████████████████████████████████████
████████████████████████████████████████████████████
████████████████████████████████████████████████
████████████████████████████████████████████
████████████████████████████████████████████
████████████████████████████████████████████████
████████████████████████████████████████████████
████████████████████████████████████████████████████
████████████████████████████████████████████████████
████████████████████████████████████████████████████
████████████████████████████████████████████████████
████████████████████████████████████████████████
████████████████████████████████████████████████████
████████████████████████████████████████████████████
████████████████████████████████████████████████████████
████████████████████████████████████████████████████████
████████████████████████████████████████████████████████
████████████████████████████████████████████████████████
████████████████████████████████████████████████████████
████████████████████████████████████████████████████████
████████████████████████████████████████████████████
████████████████████████████████████████████████████
████████████████████████████████████████████████
████████████████████████████████████████

this may or may not look bad on mobile >:3


yes i made a python script to convert a PNG into bbcode block character pixel art to put a funny little image in my FurAffinity profile bio, and while i was at it i made it output to html too.

thought it would be funny to post it here as text instead of as a png lol

it's supposed to look like this:

awful spaghetti code below:

from PIL import Image
from itertools import groupby

def clamp(x): 
  return max(0, min(x, 255))

def rgb_to_hex(r, g, b):
    return "#{0:02x}{1:02x}{2:02x}".format(clamp(r), clamp(g), clamp(b))

def convert(data, row_func):
    result = []
    for row in data:
        while len(row) > 1 and row[0][3] == 0 and row[-1][3] == 0:
            # trim transparent pixels from the outside
            row = row[1:-1]
        result.append(row_func(row))
    return '\n'.join(result)

def row_to_html(row):
    grouped_row = groupby(row)
    result = []
    for px, group in grouped_row:
        result += f"<span style=\"color: rgba({px[0]}, {px[1]}, {px[2]}, {px[3]})\">{chr(9608)*2*len(list(group))}</span>"
    return f"<div>{''.join(result)}</div>"

def im_to_html(data):
    result = "<html><body><div style=\"text-align: center; line-height: normal;\">\n"
    result += convert(data, row_to_html)
    result += '\n</div></body></html>\n'
    return result

def row_to_bbcode(row):
    grouped_row = groupby(row)
    result = []
    for px, group in grouped_row:
        if px[3] == 0:
            color = 'transparent'
        else:
            color = rgb_to_hex(px[0], px[1], px[2])
        result += f"[color={color}]{chr(9608)*2*len(list(group))}[/color]"
    return ''.join(result)

def im_to_bbcode(data):
    result = ""
    # result += "[center]"
    result += convert(data, row_to_bbcode)
    # result += "[/center]"
    return result

def main():
    im = Image.open('gabu.png')
    width = im.width
    height = im.height

    pixels = im.convert('RGBA')

    data = list(pixels.getdata())
    data = [data[(y*width):(y*width)+height] for y in range(height)]

    import sys
    sys.stdout.reconfigure(encoding='utf-8')
    print(im_to_html(data))

if __name__ == '__main__':
    main()

You must log in to comment.