HTML TO CODE
from flask import Flask, render_template, request
from PIL import Image
app = Flask(__name__)
def image_to_html(image_path):
# Open the image file
image = Image.open(image_path)
# Get image dimensions
width, height = image.size
# Initialize HTML code
html_code = f'
\n'
# Loop through pixels and generate HTML code
for y in range(height):
for x in range(width):
# Get the RGB values of the pixel
r, g, b = image.getpixel((x, y))
# Convert RGB to hex color code
color_code = f'#{r:02X}{g:02X}{b:02X}'
# Add a div with the corresponding color
html_code += f'\n'
# Close the main div
html_code += '
'
return html_code
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# Check if a file was uploaded
if 'image' in request.files:
image = request.files['image']
# Save the image temporarily
image_path = 'temp_image.png'
Comments
Post a Comment