PNG vs JPG vs WebP: When to Use Each Image Format
Lossy vs lossless compression, when transparency matters, and why WebP is replacing both PNG and JPG on the web.
Combining multiple images into a single canvas sounds simple, but the details matter more than you'd expect. Grid spacing, resolution matching, and output format all affect whether the result looks professional or like a hasty paste job.
There are two fundamental approaches to combining images, each suited to different use cases:
Images are arranged in uniform rows and columns — a 2×2 grid, a 3×1 horizontal strip, or a 1×4 vertical stack. Grid layouts enforce equal sizing, which means images may be cropped or scaled to fit the cell dimensions. This is the most common approach for:
Images are placed at arbitrary positions on a canvas, potentially overlapping. This gives full creative control but requires manual positioning. Common uses include mood boards, photo montages, and design mockups.
Under the hood, image merging uses the HTML Canvas API (or similar libraries) through a straightforward process:
How grid merging works internally:
1. Calculate output canvas size
→ total width = columns × cell width + gaps
→ total height = rows × cell height + gaps
2. For each image:
a. Load the image into memory
b. Scale/crop to fit the cell dimensions
c. Draw onto the canvas at (col × cellWidth, row × cellHeight)
3. Export the canvas to the output format (PNG, JPG, WebP)
Example: 2×2 grid, 800px cells, 10px gap
Canvas = (800 × 2 + 10) × (800 × 2 + 10) = 1610 × 1610 pxThe critical step is step 2b — how images of different sizes are adapted to fit the grid. The two strategies are cover (scale up and crop to fill the cell, like CSS object-fit: cover) and contain (scale down to fit entirely within the cell, adding padding if needed).
When combining images from different sources, resolution mismatches can create visually jarring results:
| Scenario | Problem | Solution |
|---|---|---|
| Phone photo + screenshot | Photo is 4000px wide, screenshot is 1080px | Resize the photo down before merging |
| Retina + standard display | One image is 2x pixel density, other is 1x | Normalize both to the same DPI first |
| Portrait + landscape | Aspect ratios don't match grid cells | Use cover-fit to crop, or add padding |
For print output, aim for at least 300 DPI at the final print size. For web and screen use, 72–150 DPI is sufficient. Larger canvases produce bigger files, so match the resolution to the actual output medium.
If the merged image will be shared on social media, check the platform's recommended dimensions. Instagram posts work best at 1080×1080, Twitter/X cards at 1200×675, and Facebook covers at 820×312.
The goal of image merging isn't just putting pictures next to each other — it's making them look like they were always meant to be together. Consistent sizing, matching resolution, and the right output format make the difference.
Lossy vs lossless compression, when transparency matters, and why WebP is replacing both PNG and JPG on the web.
What happens when you drag the quality slider, how DCT transforms photos, and why screenshots compress differently.
How QR encodes data in binary modules, why error correction lets you put logos in the center, and what those corner squares do.