I Built a Free PNG to WebP Converter Using Only Frontend โ Hereโs What I Learned
๐ 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
Wuyn Tiny
๐ 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?
Found this useful? Share it!
Read the Full Story
Continue reading on Dev.to
Related Stories
AI Industry Layoffs: Strategic Unionization Opportunity Amid Potential Bubble Burst
37 minutes ago
The Art of Delegation: Python Functions, Decorators, & Scope
42 minutes ago
Claude Code ใฎ็ฅใใใใๆฉ่ฝ10้ธ โ Road to Web 4.0
about 1 hour ago
2ไบบ+116ไฝใฎAI โ ๆณไบบๅใใฆใใใฃใ็พๅฎ โ Road to Web 4.0
about 1 hour ago