Created
May 30, 2023 02:59
-
-
Save mouseos/54b0dbd2eeaede6853dfd0df36888ae8 to your computer and use it in GitHub Desktop.
画像(img1.jpg)をhtmlに変換する
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 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