Oh MyUtils

Image Format Converter - Convert PNG, JPG, WebP & AVIF Online

Convert images between PNG, JPG, WebP, and AVIF formats entirely in your browser. Batch conversion, quality control, and file size comparison — no upload required.

Frequently Asked Questions

What is an image format converter and why do I need one?

An image format converter changes images from one file format to another (e.g., PNG to WebP, JPG to AVIF). This is essential for web development because modern formats like WebP and AVIF offer significantly smaller file sizes than traditional PNG and JPEG, leading to faster page load times, lower bandwidth costs, and better Core Web Vitals scores. A typical 2MB PNG image can be converted to WebP at under 500KB with minimal visual quality loss.

How do I use this image format converter?

1. Drag and drop your images onto the upload area (or click to browse files). 2. Select the target output format (PNG, JPG, WebP, or AVIF). 3. Adjust the quality slider for lossy formats (default is 80%). 4. Click 'Convert' on individual images or 'Convert All' for batch processing. 5. Review the before/after file size comparison. 6. Download individual images or use 'Download All' for a ZIP archive.

Is my image data safe? Are images uploaded to a server?

Your images are 100% safe and never leave your browser. All format conversion is performed client-side using the HTML5 Canvas API. No image data is transmitted to any server, making this tool completely private. You can even use it offline after the page loads.

What is the difference between PNG, JPG, WebP, and AVIF?

PNG is a lossless format with transparency support, best for graphics and icons but with larger file sizes. JPG/JPEG is a lossy format without transparency, best for photographs with good compression. WebP is a modern format supporting both lossy and lossless compression with transparency, typically 25-35% smaller than JPEG with 95%+ browser support. AVIF is the newest format with the best compression ratio (20-50% smaller than WebP), supporting transparency, though browser support is still growing.

Why is my converted file larger than the original?

This can happen when converting from a highly compressed format to a less efficient one (e.g., WebP to PNG) or when the original was already well-optimized. PNG output from Canvas API is always lossless and may be larger than lossy alternatives. Try using WebP or AVIF with a quality setting of 80% for the best size-to-quality ratio.

Does this tool support AVIF in all browsers?

AVIF encoding via the Canvas API is currently supported in Chrome 96+ and Edge 96+. Firefox and Safari have limited AVIF encoding support. The tool automatically detects your browser's capabilities and will disable the AVIF option if it is not supported, showing a clear message.

What happens to transparency when I convert to JPG?

JPEG does not support transparency. When converting a transparent PNG or WebP image to JPG, transparent areas will be filled with a background color (white by default). The tool allows you to choose a custom background color using the color picker that appears when JPG is selected as the output format.

Can I convert multiple images at once?

Yes, batch conversion supports up to 20 images simultaneously. All images will be converted to the same target format with the same quality settings. After conversion, use 'Download All (ZIP)' to download all converted images in a single ZIP file.

Code Examples

// Client-side image format conversion using Canvas API
async function convertImageFormat(file, outputFormat, quality = 0.8) {
  return new Promise((resolve, reject) => {
    const img = new Image();
    const url = URL.createObjectURL(file);

    img.onload = () => {
      URL.revokeObjectURL(url);

      const canvas = document.createElement('canvas');
      canvas.width = img.width;
      canvas.height = img.height;

      const ctx = canvas.getContext('2d');

      // Fill background for JPEG (no transparency support)
      if (outputFormat === 'image/jpeg') {
        ctx.fillStyle = '#ffffff';
        ctx.fillRect(0, 0, canvas.width, canvas.height);
      }

      ctx.drawImage(img, 0, 0);

      canvas.toBlob(
        (blob) => {
          if (!blob) {
            reject(new Error('Conversion failed'));
            return;
          }
          resolve({
            blob,
            originalSize: file.size,
            convertedSize: blob.size,
            inputFormat: file.type,
            outputFormat: outputFormat,
            sizeDiff: Math.round(((blob.size - file.size) / file.size) * 100),
          });
        },
        outputFormat,
        outputFormat === 'image/png' ? undefined : quality
      );
    };

    img.onerror = () => {
      URL.revokeObjectURL(url);
      reject(new Error('Failed to load image'));
    };

    img.src = url;
  });
}

// Check AVIF support
async function checkAvifSupport() {
  const canvas = document.createElement('canvas');
  canvas.width = 1;
  canvas.height = 1;
  return new Promise((resolve) => {
    canvas.toBlob(
      (blob) => resolve(blob?.type === 'image/avif'),
      'image/avif',
      0.5
    );
  });
}

// Batch conversion
async function convertBatch(files, outputFormat, quality = 0.8) {
  const results = [];
  for (const file of files) {
    try {
      const result = await convertImageFormat(file, outputFormat, quality);
      results.push({ filename: file.name, ...result });
    } catch (error) {
      results.push({ filename: file.name, error: error.message });
    }
  }
  return results;
}

// Usage
const input = document.querySelector('input[type="file"]');
input.addEventListener('change', async (e) => {
  const files = Array.from(e.target.files);
  const results = await convertBatch(files, 'image/webp', 0.8);

  results.forEach((result) => {
    if (result.error) {
      console.error(`${result.filename}: ${result.error}`);
    } else {
      console.log(
        `${result.filename}: ${result.inputFormat} -> ${result.outputFormat}, ` +
        `${result.originalSize} -> ${result.convertedSize} (${result.sizeDiff}%)`
      );
    }
  });
});

Related Tools