Last active
February 16, 2024 16:51
-
-
Save SoulFireMage/fd2fe47d753e363c1de8ecc7bf029a69 to your computer and use it in GitHub Desktop.
Ascii Art in SQL!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#how to make a silly image like thing for use in datagrids like DevExpress. Friday snap special | |
from PIL import Image | |
image = Image.open('C:\Downloadstmp\LeftAktarian75 - Copy.bmp').convert('L') # Convert to grayscale | |
image = image.resize((64, 64)) | |
# Threshold value to distinguish between '1' and ' ' | |
threshold = 128 | |
ascii_art = [] | |
for y in range(64): | |
row = '' | |
for x in range(64): | |
pixel = image.getpixel((x, y)) | |
if pixel < threshold: | |
row += '1' # Dark pixel | |
else: | |
row += ' ' | |
ascii_art.append(row) | |
# Print the ASCII art | |
for row in ascii_art: | |
print(row) | |
def generate_sql_from_ascii(ascii_art): | |
sql_statements = [] | |
for row in ascii_art: | |
row_query = "SELECT " | |
for i, char in enumerate(row, start=1): | |
if char == '1': | |
row_query += "'1' AS col{}, ".format(i) | |
else: | |
row_query += "' ' AS col{}, ".format(i) | |
row_query = row_query.rstrip(", ") | |
sql_statements.append(row_query) | |
combined_sql = " UNION ALL ".join(sql_statements) | |
return combined_sql | |
# Generate SQL | |
sql_query = generate_sql_from_ascii(ascii_art) | |
print(sql_query) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment