π Introduction
I recently built a simple online tool to convert PNG images to WebP β and I challenged myself to do it using only frontend technologies.
No backend. No file uploads to a server.
At first, it sounded easy⦠but there were a few interesting challenges along the way.
π€ Why I Built This
If you've worked with images on the web, you probably know this:
- PNG files are large
- They slow down websites
- Page speed affects SEO
WebP solves most of these problems:
- Smaller file size
- Good quality
- Supported by modern browsers
So I thought:
π Why not build a simple tool that converts PNG to WebP instantly?
βοΈ Tech Stack
I kept things simple:
- Frontend: Next.js (CSR)
- Image processing: HTMLCanvas API
- No backend at all
The idea was:
Let the browser handle everything.
π§ How It Works
The core idea is surprisingly straightforward.
- User uploads a PNG image
- Load it into an
<img>element - Draw it onto a
<canvas> - Export it as WebP
Hereβs a simplified version:
const convertToWebP = (file) => {
const img = new Image();
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
img.onload = () => {
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
const webp = canvas.toDataURL("image/webp", 0.8);
console.log(webp);
};
img.src = URL.createObjectURL(file);
};
β οΈ Challenges I Faced
1. Memory Issues
Large images can easily crash the tab or freeze the UI.
π Solution:
- Limit file size
- Resize before processing 2. Performance
Processing happens on the main thread β UI lag.
π Solution:
- Show loading state
- Consider Web Workers (future improvement) 3. Quality vs Size
canvas.toDataURL("image/webp", 0.8);
- 0.8 = good balance
- Lower β smaller file
- Higher β better quality
π Why No Backend?
I intentionally avoided using a backend because:
- Faster (no upload time)
- Better privacy (images stay on device)
- Lower cost (no server needed)
But there are trade-offs:
- Limited by browser performance
- Not ideal for large files
π Live Tool
If you want to try it, hereβs the tool I built:
π https://toolavin.com/png-to-webp
Itβs free, no signup required.
π What I Learned
- The browser is more powerful than we think
- Simple tools can still bring real value
- Performance matters more than features
Also:
Building small tools is a great way to learn and experiment.
π‘ Whatβs Next?
Iβm planning to:
- Add batch processing
- Support more formats
- Improve performance with Web Workers
π Final Thoughts
This was a small project, but I learned a lot from it.
If you're thinking about building a tool:
π Just start simple.
You donβt need a complex backend to create something useful.
π¬ Feedback Welcome
Would love to hear your thoughts or suggestions π
What would you improve?
Top comments (0)