Prompt
How do I compress PNGs for web without visible blur?
Latest observation
To compress PNGs for the web without visible blur, the key is to preserve sharp edges and avoid unnecessary resizing or lossy conversion. PNG is already a lossless format, so “compressing” usually means reducing file size without changing image quality.
Best practices
1. Use the right PNG type
- PNG-24: Best for photos/screenshots with many colors and transparency.
- PNG-8: Great for logos, icons, flat graphics with few colors. Much smaller, but limited to 256 colors.
If your image is a logo, icon, or flat UI graphic, converting to PNG-8 can reduce size a lot with no visible blur if the palette is good.
2. Avoid resizing up
- Never enlarge an image for the web.
- If you must scale, scale down using a high-quality resampling method, then save.
Blur usually comes from interpolation during resizing, not from compression itself.
3. Use lossless PNG optimizers
These reduce file size by improving compression and metadata, without changing pixels:
- optipng
- oxipng
- pngcrush
- zopflipng
Example:
oxipng -o 6 --strip all image.png
Or:
optipng -o7 image.png
These typically reduce size safely.
4. Reduce colors when appropriate
For flat graphics:
- Convert to indexed color / palette PNG
- Use a tool that lets you choose a good number of colors, like 16, 32, 64, or 128
Example with ImageMagick:
magick input.png -colors 64 -strip output.png
Try different palette sizes and inspect the result.
5. Keep transparency only if needed
Transparency adds size. If the background is always the same on your site, consider removing alpha and using a solid background.
6. Strip metadata
Remove:
- EXIF
- ICC profiles
- comments
- timestamps
This can save space and doesn’t affect visual quality.
7. For screenshots and UI graphics, consider WebP or AVIF
If browser support is acceptable, these often outperform PNG in size:
- WebP lossless for sharp graphics
- AVIF for even smaller files in many cases
But if you need PNG specifically, stick with lossless optimization and palette reduction.
What causes visible blur?
- Upscaling
- Aggressive lossy quantization
- Using JPEG instead of PNG for sharp graphics
- Saving with poor resampling after resizing
- Too few colors in PNG-8
Safe workflow
- Resize only if necessary, and only down.
- Strip metadata.
- Optimize with
oxipngoroptipng. - If it’s a logo/icon, test PNG-8 palette reduction.
- Compare visually before deploying.
Recommended tools
- GUI: Photoshop, Affinity Photo, GIMP, TinyPNG
- CLI:
oxipng,optipng,pngcrush, ImageMagick
If you want, I can give you:
- a one-line command for Linux/macOS/Windows,
- a Photoshop/GIMP workflow, or
- a best settings guide for logos vs screenshots.