generate_icons.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import os
  2. from PIL import Image, ImageDraw, ImageFont
  3. def create_icon(name, color, text_symbol, filename):
  4. size = (81, 81)
  5. img = Image.new('RGBA', size, (255, 255, 255, 0))
  6. draw = ImageDraw.Draw(img)
  7. # Draw a simple shape or text
  8. # Since we don't have a guaranteed font, we'll draw shapes
  9. # Center
  10. cx, cy = size[0] // 2, size[1] // 2
  11. r = 30
  12. if 'home' in name:
  13. # Draw a house
  14. points = [(cx, cy-r), (cx-r, cy), (cx+r, cy)]
  15. draw.polygon(points, fill=color)
  16. draw.rectangle([cx-r+10, cy, cx+r-10, cy+r], fill=color)
  17. elif 'order' in name:
  18. # Draw a document
  19. draw.rectangle([cx-20, cy-30, cx+20, cy+30], fill=color)
  20. # Lines
  21. draw.line([cx-10, cy-10, cx+10, cy-10], fill=(255,255,255,255), width=3)
  22. draw.line([cx-10, cy+10, cx+10, cy+10], fill=(255,255,255,255), width=3)
  23. elif 'mine' in name:
  24. # Draw a person
  25. draw.ellipse([cx-15, cy-35, cx+15, cy-5], fill=color)
  26. draw.pieslice([cx-30, cy, cx+30, cy+60], 180, 360, fill=color)
  27. img.save(filename)
  28. print(f"Generated {filename}")
  29. def main():
  30. base_dir = r"C:\Users\admin\Desktop\宠物需求\宠物管理系统\performer_app\static\tabbar"
  31. if not os.path.exists(base_dir):
  32. os.makedirs(base_dir)
  33. gray = (153, 153, 153, 255) # #999999
  34. orange = (255, 87, 34, 255) # #FF5722
  35. create_icon("home", gray, "H", os.path.join(base_dir, "home.png"))
  36. create_icon("home-active", orange, "H", os.path.join(base_dir, "home-active.png"))
  37. create_icon("order", gray, "O", os.path.join(base_dir, "order.png"))
  38. create_icon("order-active", orange, "O", os.path.join(base_dir, "order-active.png"))
  39. create_icon("mine", gray, "M", os.path.join(base_dir, "mine.png"))
  40. create_icon("mine-active", orange, "M", os.path.join(base_dir, "mine-active.png"))
  41. if __name__ == "__main__":
  42. main()