omniparser-api / create_test_image.py
Netrava's picture
Upload 4 files
86062d2 verified
from PIL import Image, ImageDraw, ImageFont
import os
def create_test_ui_image():
"""Create a simple test UI image with buttons and text"""
# Create a new image with white background
width, height = 800, 600
image = Image.new('RGB', (width, height), color='white')
draw = ImageDraw.Draw(image)
# Try to load a font, use default if not available
try:
font = ImageFont.truetype("arial.ttf", 20)
small_font = ImageFont.truetype("arial.ttf", 16)
except IOError:
font = ImageFont.load_default()
small_font = ImageFont.load_default()
# Draw a header
draw.rectangle([(0, 0), (width, 60)], fill='#4285F4')
draw.text((20, 15), "Test UI Application", fill='white', font=font)
# Draw a sidebar
draw.rectangle([(0, 60), (200, height)], fill='#F1F1F1')
# Draw menu items in sidebar
menu_items = ["Home", "Profile", "Settings", "Help", "Logout"]
for i, item in enumerate(menu_items):
y = 100 + i * 50
# Highlight one item
if item == "Settings":
draw.rectangle([(10, y-10), (190, y+30)], fill='#E1E1E1')
draw.text((20, y), item, fill='black', font=font)
# Draw main content area
draw.text((220, 80), "Welcome to the Test UI", fill='black', font=font)
# Draw a form
draw.text((220, 150), "Please enter your information:", fill='black', font=font)
# Draw form fields
fields = ["Name", "Email", "Phone"]
for i, field in enumerate(fields):
y = 200 + i * 60
draw.text((220, y), f"{field}:", fill='black', font=font)
draw.rectangle([(320, y-5), (700, y+25)], outline='black')
# Draw buttons
draw.rectangle([(220, 400), (320, 440)], fill='#4285F4')
draw.text((240, 410), "Submit", fill='white', font=font)
draw.rectangle([(340, 400), (440, 440)], fill='#9E9E9E')
draw.text((360, 410), "Cancel", fill='white', font=font)
# Draw a checkbox
draw.rectangle([(220, 470), (240, 490)], outline='black')
draw.text((250, 470), "Remember me", fill='black', font=small_font)
# Save the image
os.makedirs("static", exist_ok=True)
image_path = "static/test_ui.png"
image.save(image_path)
print(f"Test UI image created at {image_path}")
return image_path
if __name__ == "__main__":
create_test_ui_image()