Spaces:
Runtime error
Runtime error
File size: 1,965 Bytes
8b8fa39 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | from PIL import Image, ImageDraw, ImageFont
import os
# Create sample prescription
width, height = 600, 800
image = Image.new('RGB', (width, height), 'white')
draw = ImageDraw.Draw(image)
# Use default font
try:
# Try to load a better font if available
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 16)
header_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 20)
except:
font = ImageFont.load_default()
header_font = ImageFont.load_default()
# Draw prescription content
y_pos = 50
draw.text((50, y_pos), "CITY HOSPITAL - EMERGENCY", fill='black', font=header_font)
y_pos += 40
draw.text((50, y_pos), "Dr. Test Danger, MD", fill='black', font=font)
y_pos += 30
draw.text((50, y_pos), "License: 999999", fill='black', font=font)
y_pos += 50
draw.text((50, y_pos), "Patient: Little Timmy", fill='black', font=font)
y_pos += 30
draw.text((50, y_pos), "Age: 5 Years Old", fill='black', font=font)
y_pos += 25
draw.text((50, y_pos), "Date: 12/04/2025", fill='black', font=font)
y_pos += 50
draw.text((50, y_pos), "Rx:", fill='black', font=header_font)
y_pos += 40
# High Dosage 1
draw.text((70, y_pos), "1. Paracetamol 2000mg", fill='black', font=font)
y_pos += 25
draw.text((70, y_pos), " Take 2 tablets every 4 hours", fill='black', font=font)
y_pos += 40
# High Dosage 2
draw.text((70, y_pos), "2. Amoxicillin 1000mg", fill='black', font=font)
y_pos += 25
draw.text((70, y_pos), " Take 1 tablet 3 times daily", fill='black', font=font)
y_pos += 40
# High Dosage 3
draw.text((70, y_pos), "3. Ibuprofen 800mg", fill='black', font=font)
y_pos += 25
draw.text((70, y_pos), " Take 1 tablet 4 times daily", fill='black', font=font)
y_pos += 40
draw.text((50, y_pos + 50), "Signature: _________________", fill='black', font=font)
# Save
output_path = "sample_prescriptions/overdose_sample.jpg"
image.save(output_path, "JPEG", quality=95)
print(f"Created {output_path}")
|