- Knowledge
- technology
- OOP
- Tips
- Programming
- Tips
- Tutorial
- SEO
- Ranking
- Knowledge
- Special Day
- Seo
- Bug
- Data science
- Seo
- artificial intelligence
- Machine Learning
- Robotics
- happyNewYear2021
- newYearEve
- 2021
- Automation
- Smart Home
- Career
- Best Practices
- Git
- Logging
- Web Fundamentals
- DNS
- HTTPS
- Performance
- AI Tools
- ChatGPT
- Claude
- Gemini
- Laravel
- Eloquent
- MySQL
- HTTPS
- TLS
- Web Security
- Certificates
- Developer Life
- Debugging
- Docker
- DevOps
- Transactions
- Queues
- LLMs
- AI
- AI Coding
- Developer Tools
- React Native
- Expo
- Kate PMS
- Mobile Apps
- Laravel
- Authentication
- Sanctum
- Cookies
- API Design
- Payments
- Idempotency
- DeepSeek
- Open Source AI
- LLMs
- AI News
- Git
- Version Control
- AI Coding
- Prompting
- PHP
- Checklist
- MCP
- AI Agents
- OpenAI
- Architecture
- Microservices
- Modular Monolith
- Estimation
- Developer Life
- Project Planning
- Humour
- OAuth
- OpenID Connect
- Authentication
- Embeddings
- Vector Search
- RAG
- pgvector
- OpenAI
- GPT-4.1
- Codex CLI
- Events
- Testing
- Clean Code
- Maintainability
- Code Review
- Webhooks
- API
- Security
- Claude Code
- Workflow
- AI
- LLM
- Prompt Injection
- Mobile
- React
- Networking
- TCP
- UDP
- HTTP/3
- CLAUDE.md
- AWS
- Cloud Security
- Backups
- PHPUnit
- Software Engineering
- Leadership
- Communication
- RAG
- Embeddings
- AI Engineering
- IT Infrastructure
- Networking
- Access Control
- CI/CD
- GitHub Actions
- Gemini CLI
- Claude Code
- JavaScript
- Async/Await
- Node.js
- Promises
- Security
- Cryptography
- Passwords
- MySQL
- Database
- Vibe Coding
- Software Quality
- DNS
- Code Reading
- Onboarding
- Productivity
- Background Jobs
- Developer Humour
- Estimates
- Dev Life
- JWT
- o3-mini
- DeepSeek R1
- Rate Limiting
- Kate PMS
- E-Signing
- Audit Trail
- REST
- GraphQL
- API Design
- Laravel 12
- Upgrade Guide
- Open Source
- Self-Hosting
- Task Scheduling
- Cron
- Secrets
- CORS
- PHP
- PHP-FPM
- OPcache
- GitHub Copilot
- Software Architecture
- Engineering
- TypeScript
- JavaScript
- Type Safety
- AI Security
- React Native
- Product Design
- AI Agents
- Kiro
- Queues
- Redis
- RabbitMQ
- AWS SQS
- Nginx
- Apache
- GPT-5
- gpt-oss
- Clean Code
- Architecture
- Naming
- Documentation
- Career
- ADR
- Teamwork
- Supply Chain
- Kate HRM
- HR Software
- Permissions
- System Design
- Pagination
- SSH
- Linux
- Big O
- Databases
- Laravel Boost
- MCP
- Developer Skills
- Validation
- Databases
- Indexes
- Code Quality
- Deployment
- Developer Humour
- Feature Flags
- Code Review
- Pull Requests
- Docker
- Cursor
- Authorization
- RBAC
- Gemini
- Long Context
- PHP 8.4
- Caching
- Dependency Injection
- Web Performance
- Browser
- CSS
- Database
- Migrations
- ChatGPT
- AI for Developers
- Monitoring
- On-Call
- REST
- Backend
- SQL
- NoSQL
- Database Design
- Coding Agents
- Claude 4
- API Resources
- REST API
- Load Balancing
- Scaling
- AWS
- AI Tools
- Claude
- Sora 2
- CTE
- 2FA
- TOTP
- Programming Languages
- Prompts
- Developer Workflow
- API Gateway
- APIs
- Passport
- API Auth
- Learning
- Burnout
- Developer Growth
- Web Development
- SEO
- Kate Mall
- ChatGPT Atlas
- Agent Skills
- Middleware
- Laravel 12
- Collections
- Context Window
- Monitoring
- Commit Messages
- Self Review
- Growth
- Regex
- Programming Basics
- Text Processing
- Database Design
- Normalization
- Linux
- Server Security
- Linux Foundation
- Open Standards
- Legacy Code
- Documentation
- AI Workflow
- File Uploads
- Test Data
- Hashing
- Performance
- Caching
- Enums
- Scope Creep
- Estimation
- Codex
- Gemini CLI
- Timezones
- Carbon
- Bugs
- PHP 8.5
- Gemini 3
- GPT-5.1
- Data Integrity
- Event Loop
- Async
- Opus 4.5
- AI Models
- React
- Forms
- Frontend
- Backups
- AI Images
- DALL-E
- Midjourney
- Race Conditions
- Concurrency
- Legacy Code
- Refactoring
- Senior Engineer
- Scope
- LLM
- CDN
- Web
- Sub-Agents
- Soft Deletes
- Audit Log
- Concurrency
- AI Learning
- NestJS
- AI Evals
- Policies
- SPF DKIM DMARC
- Unicode
- UTF-8
- Knowledge Graph
- Value Objects
- Technical Debt
- Feature Flags
- Laravel Pennant
- Deployment
- Copilot
- Composer
- Dependencies
- Artisan
- Automation
- AWS S3
- Object Storage
- Cloud
- Small Language Models
- Ollama
- Production
- Sessions
- HTTP
- Mentoring
- SQL
- Virtual Machines
- Web Development
- HTTP/2
- QUIC
- Web Performance
- AI Integration
- LLM API
- SOLID
- OOP
- Hosting
- Serverless
- Merge Conflicts
- Temperature
- AI Development
- Reverse Proxy
- Nginx
- Infrastructure
- Verification
- Passkeys
- WebAuthn
- Teams
- Communication
- Stakeholders
- Monorepo
- CI/CD
- Versioning
- JSON Schema
- Livewire
- Inertia
- Meetings
- Distributed Systems
- Privacy
- Full-Stack
- T-Shaped Skills
- Money
- Notifications
- Web Security
- HTTP Headers
- CSP
- Function Calling
- Load Testing
- k6
- Data Extraction
- Debugging
- WebSockets
- SSE
- Real-Time
- Laravel Reverb
- Infrastructure as Code
- Terraform
- Side Projects
- Laravel Pint
- OpenAPI
- Swagger
- UX
- Multimodal
- Jest
- Pair Programming
- APIs
- Rate Limiting
- Resilience
- Dev Humour
- Design Tokens
- JWT
- API Keys
- Sessions
- PHPStan
- Rector
- Incidents
- Reporting
- Dashboards
- Zero Trust
- IAM
- Search
- Laravel Scout
- Junior Developers
- Mentoring
- Images
- WebP
- AVIF
- Bug Reports
- Let's Encrypt
- Design Docs
- Software Design
- Observers
- Replication
- Accountability
- Data Structures
- Reliability
- LLM Memory
- Error Handling
- Payments
- Payment Gateway
- Webhooks
- PCI DSS
- Observability
- OpenTelemetry
- Personal Brand
- Writing
- Conventions
- Dates
- Scheduling
- Disaster Recovery
- Compression
- Brotli
- Deadlines
- Developer Habits
- State Machines
- Tech Roles
- UUID
- ULID
- Horizon
- Planning
- Engineering Culture
- Ownership
- Soft Skills
- Socialite
- Cost Control
- Collations
- Unicode
- Octane
- PostgreSQL
How Image Formats Work: JPEG, PNG, WebP and AVIF Explained
About Post
The page is slow. You open the network tab expecting a heavy JavaScript bundle, and instead you find the culprit sitting quietly at the top: the homepage banner. A photo. Saved as a PNG. At 4000 pixels wide. Being shown in a box 1200 pixels wide, or 400 on a phone.
Images are usually the heaviest thing on a web page, and the easiest to fix, once you understand what the formats actually do. Each one makes different trade-offs, and choosing well is less about memorising rules and more about knowing what kind of picture you have.
Two ways to shrink a picture
Every image format compresses, but in one of two ways:
- Lossless compression is like zipping a file. Unzip it and you get back exactly the same pixels. It works by finding patterns and repetition, so it's brilliant for flat colours and sharp edges, and poor for photos, where almost no two neighbouring pixels are identical.
- Lossy compression throws information away, carefully. It removes detail your eyes are unlikely to notice. The result is much smaller files, at the cost of some quality you choose with a quality setting.
The whole game is matching the method to the content: lossy for photos, lossless for screenshots, logos and anything with text.
The formats, one by one
JPEG: the old reliable for photos
JPEG splits the image into small 8×8 pixel blocks and describes each block as a mix of smooth patterns, keeping the strong patterns and discarding the fine ones. It also stores colour at lower resolution than brightness, because our eyes are far more sensitive to brightness detail.
That's why JPEG is great for photos and terrible for text and sharp lines: you get blurry "ringing" around edges and visible blocks at low quality. It has no transparency, and every re-save loses a bit more quality, so always edit from the original, not from the last JPEG.
PNG: lossless and transparent
PNG is lossless and supports a full alpha channel, so edges can fade smoothly into any background. It's the right choice for screenshots, diagrams, UI elements and images with text. For photos, it's the wrong tool: the files come out many times larger than a JPEG that looks the same.
WebP: the all-rounder
WebP, developed by Google, does both: a lossy mode for photos and a lossless mode for graphics, with transparency and animation in either. Lossy WebP is generally smaller than a JPEG of similar visual quality, and lossless WebP is generally smaller than PNG. Every modern browser supports it, which makes it a safe default today.
AVIF: the newest, and the smallest
AVIF stores a still image using the AV1 video codec's compression. It usually beats WebP at the same visual quality, especially at low file sizes, and supports transparency, HDR and wide colour. The trade-offs: encoding is noticeably slower and more CPU-hungry, and some older devices and browsers still don't support it, so you serve it with a fallback.
And the honourable mentions
SVG isn't pixels at all, it's a description of shapes. For logos and icons it's unbeatable: tiny, and sharp at any size. GIF is limited to 256 colours and usually produces huge files for animation; a short muted video or an animated WebP is almost always better.
| Format | Compression | Transparency | Best for |
|---|---|---|---|
| JPEG | Lossy | No | Photos, universal fallback |
| PNG | Lossless | Yes | Screenshots, graphics with text |
| WebP | Both | Yes | Almost everything on the web |
| AVIF | Both (mostly used lossy) | Yes | Photos where every kilobyte counts |
| SVG | Vector | Yes | Logos, icons, simple illustrations |
The bigger win is usually size, not format
Here's the part people skip. Switching a JPEG to WebP helps. Not sending a 4000-pixel image to a 400-pixel screen helps far more. Pixel count grows with the square of the width, so an image twice as wide as needed carries roughly four times the pixels.
The browser can pick the right size for you, and the right format, if you offer the options:
<picture>
<source type="image/avif" srcset="/img/hero-800.avif 800w, /img/hero-1600.avif 1600w" sizes="100vw">
<source type="image/webp" srcset="/img/hero-800.webp 800w, /img/hero-1600.webp 1600w" sizes="100vw">
<img src="/img/hero-1600.jpg" alt="Lobby of the new building"
width="1600" height="800" fetchpriority="high">
</picture>
The browser uses the first format it supports and the smallest file that fits the screen. Two details matter here. The width and height attributes let the browser reserve space before the image loads, so the page doesn't jump around. And use loading="lazy" for images further down the page, but not for the main image at the top; lazy-loading that one makes the most important content arrive later.
The quick rule: photos as AVIF or WebP with a JPEG fallback, graphics and screenshots as WebP or PNG, logos and icons as SVG, and always resize to the size you actually display.
Converting uploads on the server
For user uploads (property photos, profile pictures, product images), convert and resize once on upload, ideally in a queued job. PHP's GD extension can write both modern formats:
$image = imagecreatefromjpeg($originalPath);
$image = imagescale($image, 1600); // width 1600, height keeps the ratio
imagewebp($image, $webpPath, 80); // quality 0-100
imageavif($image, $avifPath, 60); // PHP 8.1+, needs GD built with AVIF support
This is simplified, but it shows a useful side effect: re-encoding drops the original's metadata. Photos from phones often carry EXIF data including GPS location, which you rarely want to publish. The catch is that EXIF also stores the photo's orientation, so read it and rotate the image before re-encoding, or some phone photos will appear sideways. Libraries like Intervention Image handle these details for you.
The cheat sheet
- Lossy for photos, lossless for sharp edges and text.
- WebP is the safe modern default; AVIF is smaller but slower to encode, so serve it with a fallback.
- Never serve a PNG photo or a JPEG screenshot.
- Resize to display size and use
srcset. That's usually the biggest saving. - Set
widthandheight, lazy-load below the fold, not the hero. - Strip metadata from uploads, but respect orientation first.
What's the heaviest image you've found hiding on a production page? I suspect most of us have a PNG photo somewhere we'd rather not talk about.

Be first to comment it...