create_logos.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env python3
  2. """
  3. 创建简单的Logo占位符图片
  4. 需要安装PIL/Pillow: pip install Pillow
  5. """
  6. from PIL import Image, ImageDraw, ImageFont
  7. import os
  8. def create_gsszyy_logo():
  9. """创建甘肃省中医院Logo"""
  10. # 创建图片
  11. img = Image.new('RGB', (400, 200), color='#667eea')
  12. draw = ImageDraw.Draw(img)
  13. # 尝试使用系统字体,如果失败则使用默认字体
  14. try:
  15. font = ImageFont.truetype("/System/Library/Fonts/PingFang.ttc", 60)
  16. font_small = ImageFont.truetype("/System/Library/Fonts/PingFang.ttc", 30)
  17. except:
  18. font = ImageFont.load_default()
  19. font_small = ImageFont.load_default()
  20. # 绘制文字
  21. text = "中医院"
  22. text2 = "甘肃省中医院"
  23. # 计算文字位置(居中)
  24. bbox = draw.textbbox((0, 0), text, font=font)
  25. text_width = bbox[2] - bbox[0]
  26. text_height = bbox[3] - bbox[1]
  27. position = ((400 - text_width) // 2, (200 - text_height) // 2 - 10)
  28. bbox2 = draw.textbbox((0, 0), text2, font=font_small)
  29. text_width2 = bbox2[2] - bbox2[0]
  30. position2 = ((400 - text_width2) // 2, position[1] + 70)
  31. # 绘制
  32. draw.text(position, text, fill='white', font=font)
  33. draw.text(position2, text2, fill='white', font=font_small)
  34. # 保存
  35. img.save('frontend/public/logo-gsszyy.jpg')
  36. print("已创建: frontend/public/logo-gsszyy.jpg")
  37. def create_square_logo():
  38. """创建方形Logo"""
  39. # 创建图片(正方形)
  40. img = Image.new('RGB', (200, 200), color='#667eea')
  41. draw = ImageDraw.Draw(img)
  42. # 尝试使用系统字体
  43. try:
  44. font = ImageFont.truetype("/System/Library/Fonts/PingFang.ttc", 100)
  45. except:
  46. font = ImageFont.load_default()
  47. # 绘制文字
  48. text = "中"
  49. bbox = draw.textbbox((0, 0), text, font=font)
  50. text_width = bbox[2] - bbox[0]
  51. text_height = bbox[3] - bbox[1]
  52. position = ((200 - text_width) // 2, (200 - text_height) // 2)
  53. draw.text(position, text, fill='white', font=font)
  54. # 保存
  55. img.save('frontend/public/logo.jpg')
  56. print("已创建: frontend/public/logo.jpg")
  57. if __name__ == '__main__':
  58. print("开始创建Logo占位符...")
  59. create_gsszyy_logo()
  60. create_square_logo()
  61. print("完成!")