Created
May 10, 2024 19:56
-
-
Save chadjemmett/2d7c70ffb14e8f6ed143199ad282e7f1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from openpyxl import Workbook | |
from openpyxl.styles import PatternFill | |
from openpyxl.utils import get_column_letter | |
from PIL import Image | |
im = Image.open('logo-small.png') | |
pix = im.load() | |
WIDTH = im.size[0] | |
HEIGHT = im.size[1] | |
print(pix[30, 100]) | |
wb = Workbook() | |
ws = wb.active | |
rows = [] | |
d = [["%02x%02x%02x%02x" % pix[x, y] for x in range(0, WIDTH)] for y in range(0, HEIGHT)] | |
for i in range(0, HEIGHT): | |
for k in range(0, WIDTH): | |
ws.cell(i+1, k+1).fill = PatternFill('solid', fgColor=d[i][k]) | |
for i in range(1, HEIGHT + 1): | |
ws.row_dimensions[i].height = 1 | |
for i in range(1, WIDTH + 1): | |
ws.column_dimensions[get_column_letter(i)].width = 1 | |
# This packages up columns in an iterable form | |
# c = ws.iter_cols(min_row=1, min_col=1, max_col=16) | |
# ws.column_dimensions['A'].width = 3 | |
wb.save("logo.xlsx") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment