DEV Community

Wuyn Tiny
Wuyn Tiny

Posted on

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

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.

  1. User uploads a PNG image
  2. Load it into an <img> element
  3. Draw it onto a <canvas>
  4. 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);
};
Enter fullscreen mode Exit fullscreen mode

โš ๏ธ 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);
Enter fullscreen mode Exit fullscreen mode
  • 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)