Make this photo best quality and turn into pdf
mkdir -p /tmp/workspace/pathway-pdf && cd /tmp/workspace/pathway-pdf && curl -s -o original.png "https://d361swluvexzqs.cloudfront.net/chats-attachments/1000108420-1785751835368-ed0ox8.png" && python3 -c " from PIL import Image img = Image.open('original.png') print('Original size:', img.size) print('Mode:', img.mode) print('Format:', img.format) "
cd /tmp/workspace/pathway-pdf && python3 -c " from PIL import Image, ImageFilter, ImageEnhance from reportlab.lib.pagesizes import A4, landscape from reportlab.platypus import SimpleDocTemplate from reportlab.lib.units import inch from reportlab.platypus import Image as RLImage import io # Open and enhance image img = Image.open('original.png').convert('RGBA') # Upscale 3x for best quality using high-quality Lanczos resampling scale = 3 new_w = img.width * scale new_h = img.height * scale img_upscaled = img.resize((new_w, new_h), Image.LANCZOS) # Enhance sharpness sharpener = ImageEnhance.Sharpness(img_upscaled) img_sharp = sharpener.enhance(1.4) # Enhance contrast slightly contraster = ImageEnhance.Contrast(img_sharp) img_contrast = contraster.enhance(1.1) # Flatten RGBA -> RGB with white background background = Image.new('RGB', img_contrast.size, (255, 255, 255)) background.paste(img_contrast, mask=img_contrast.split()[3]) enhanced = background # Save high-quality enhanced PNG enhanced.save('enhanced.png', 'PNG', dpi=(300, 300)) print('Enhanced size:', enhanced.size) # Now create PDF using reportlab - fit image to A4 landscape with margins from reportlab.lib.pagesizes import A4 from reportlab.lib.units import mm from reportlab.pdfgen import canvas # Page dimensions page_w, page_h = A4 # portrait A4: 595 x 842 pts margin = 15 * mm # Image dimensions in pixels img_w_px, img_h_px = enhanced.size dpi = 300 img_w_pt = img_w_px / dpi * 72 # convert px to points img_h_pt = img_h_px / dpi * 72 # Available area avail_w = page_w - 2 * margin avail_h = page_h - 2 * margin # Scale to fit scale_w = avail_w / img_w_pt scale_h = avail_h / img_h_pt scale = min(scale_w, scale_h) final_w = img_w_pt * scale final_h = img_h_pt * scale # Center on page x = (page_w - final_w) / 2 y = (page_h - final_h) / 2 print(f'PDF page: {page_w:.1f} x {page_h:.1f} pts') print(f'Image on page: {final_w:.1f} x {final_h:.1f} pts at ({x:.1f}, {y:.1f})') c = canvas.Canvas('summary_of_pathways.pdf', pagesize=A4) c.setTitle('Summary of Metabolic Pathways') c.setAuthor('Enhanced by Orris') c.setSubject('Metabolic Pathways Summary Diagram') c.drawImage('enhanced.png', x, y, width=final_w, height=final_h, preserveAspectRatio=True) c.save() print('PDF saved successfully!') import os print('File size:', os.path.getsize('summary_of_pathways.pdf'), 'bytes') "
summary of pathways
PDF Document · PDF