Skip to content

Instantly share code, notes, and snippets.

@mouseos
Created May 30, 2023 02:59
Show Gist options
  • Save mouseos/54b0dbd2eeaede6853dfd0df36888ae8 to your computer and use it in GitHub Desktop.
Save mouseos/54b0dbd2eeaede6853dfd0df36888ae8 to your computer and use it in GitHub Desktop.
画像(img1.jpg)をhtmlに変換する
from PIL import Image
image = Image.open("img1.jpg")
width, height = image.size
pixels = image.load()
print( "<style>.a{display:flex;} .b{width:1px; height:1px;}</style>")
for i in range(height):
print("<div class='a'>")
for j in range(width):
r, g, b = pixels[j, i] # 画像のRGB値を取得
hexcolor = "#" + "%02x%02x%02x" % (r, g, b)
print('<div class="b" style="background-color:'+hexcolor+';"></div>')
print("</div>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment