from PIL import Image, ImageDraw, ImageFont import os def annotate_page(page_num, img_path, annotations, output_path): img = Image.open(img_path) draw = ImageDraw.Draw(img) # Try to use a Chinese font font_paths = [ 'C:/Windows/Fonts/simhei.ttf', 'C:/Windows/Fonts/simsun.ttc', ] font_path = None for fp in font_paths: if os.path.exists(fp): font_path = fp break if font_path: try: font = ImageFont.truetype(font_path, 16) font_small = ImageFont.truetype(font_path, 13) except: font = ImageFont.load_default() font_small = ImageFont.load_default() else: font = ImageFont.load_default() font_small = ImageFont.load_default() for rect, text in annotations: # Draw red rectangle draw.rectangle(rect, outline='red', width=4) # Draw annotation text above the rectangle if text: draw.text((rect[0], rect[1] - 22), text, fill='red', font=font_small) img.save(output_path) print(f'Saved: {output_path}') # Page 2: Summary section annotate_page( 2, 'D:/workspace/cfc/web/img/ref-screenshots/cell-inflammation-p2.png', [ # SUMMARY box (around y=350-700) ((60, 340, 1640, 700), 'SUMMARY: 肥胖导致慢性全身性炎症,引起胰岛素抵抗(IR) -> \u03b2细胞功能障碍 -> 2型糖尿病(T2D)'), # Paragraph about macrophages being the ultimate driver ((60, 720, 1640, 940), '促炎巨噬细胞在代谢组织中的募集和活化,是慢性低度炎症的终极驱动力') ], 'D:/workspace/cfc/web/img/ref-screenshots/cell-inflammation-p2-annotated.png' ) # Page 3: Immunometabolism annotate_page( 3, 'D:/workspace/cfc/web/img/ref-screenshots/cell-inflammation-p3.png', [ # Immunometabolism term ((60, 110, 1640, 410), '"免疫代谢"(immunometabolism):炎症与代谢缺陷之间的相互作用'), # Drug limitation ((60, 440, 1640, 700), '所有降糖药中仅3类能预防并发症;除二甲双胍外,其他药物均不能延缓糖尿病进展') ], 'D:/workspace/cfc/web/img/ref-screenshots/cell-inflammation-p3-annotated.png' ) # Page 4: Inflammatory signaling mechanism annotate_page( 4, 'D:/workspace/cfc/web/img/ref-screenshots/cell-inflammation-p4.png', [ # TNF-alpha and IKK/NF-kB pathway ((60, 100, 1640, 420), 'TNF-\u03b1 激活 JNK 和 IKK\u03b2 -> NF-\u03baB 核转位 -> 促炎细胞因子增加'), # Inflammasome ((60, 440, 1640, 700), '炎症小体(inflammasome)被葡萄糖和游离脂肪酸激活 -> 产生活性 IL-1\u03b2') ], 'D:/workspace/cfc/web/img/ref-screenshots/cell-inflammation-p4-annotated.png' ) # Page 5: Macrophage polarization in obese vs lean annotate_page( 5, 'D:/workspace/cfc/web/img/ref-screenshots/cell-inflammation-p5.png', [ # M1-like macrophages in obesity ((60, 100, 1640, 380), '肥胖时巨噬细胞向促炎M1样极化 -> 释放促炎细胞因子 -> 降低胰岛素信号'), # Omega-3 inhibits inflammation ((60, 400, 1640, 660), 'Omega-3脂肪酸(GPR120受体)抑制M1样极化;饱和脂肪酸(TLR4)促进M1样极化'), # Crown-like structures ((60, 680, 1640, 900), '肥胖巨噬细胞聚集在萎缩脂肪细胞周围形成"冠状结构"') ], 'D:/workspace/cfc/web/img/ref-screenshots/cell-inflammation-p5-annotated.png' ) print('All annotations done.')