Posts

Showing posts from 2025

Compress a Folder of Images with Python

Compress a Whole Folder of Images with Python (Resize + Subfolders + Smart PNG→JPEG) If you keep images for a blog, documentation, or a project folder, file size becomes a problem fast. Big images slow down pages, take space, and make sharing annoying. This script automates the cleanup: it walks through a folder (and subfolders), optionally resizes images to a max width, compresses JPEGs, compresses PNGs, and can convert PNG to JPEG when it actually makes sense. When this is useful Before publishing: shrink images for faster blog load times. Docs + screenshots: reduce size without manually exporting every file. Photo folders: compress camera images and keep a clean “compressed” copy. Automation: run it after exporting images from tools like Snipping Tool, Photoshop, or PowerPoint. What it does Walk subfolders automatically and keeps the same folder structure in the output. Resize to a max width (keeps aspect ratio, never upscales). Compress JPEG us...

Testing with Pytest

Image
Pytest fixtures: clean tests without the ceremony Pytest makes testing feel less like a chore and more like a safety net—especially once fixtures enter the picture. Meta description suggestion: Learn how Pytest fixtures and markers help you write clean, isolated tests that scale—from simple unit tests to large CI pipelines. Quick jumps Why Pytest clicks The testing problem Using fixtures the right way Markers for test control Pros & cons Wrap-up Why Pytest clicks Pytest is one of those tools that feels obvious after you’ve used it for a bit. Tests are just functions. Assertions read like normal Python. And when you need context—database sessions, config, mock data—you reach for fixtures instead of duct tape. The big idea Pytest fixtures handle setup and teardown for you, so eac...

Generate a PDF Invoice from a Web Form with Flask + WeasyPrint

Generate a PDF Invoice from a Web Form with Flask + WeasyPrint If you already collect invoice details in a simple web form, the next step is usually: generate a clean PDF and download it. This Flask + WeasyPrint setup does exactly that. User submits a form, Flask renders an HTML invoice template, and WeasyPrint converts that HTML into a PDF you can download right away. Typical use cases Quick internal invoices (freelance, side projects, small business) Generate PDFs from structured form data (quotes, receipts, reports) Create consistent PDFs using HTML/CSS instead of “drawing” PDFs manually Install pip install flask weasyprint Note: WeasyPrint may require OS-level libraries depending on your system (common on Linux). If install fails, check the WeasyPrint docs for your OS. Improved script (safer, cleaner, returns PDF download) Changes from the original: Returns the PDF as a download instead of saving a fixed invoice.pdf on disk Basic input cleanup + ...