QR code images are returned as base64-encoded data URLs in the API responses. This guide shows you how to download and save QR codes in various formats.
No Separate Download EndpointQR code images are included directly in the response from:The image data is provided as a base64-encoded PNG data URL that you can convert to any format client-side.

Understanding the Data URL Format

The API returns QR codes as data URLs in this format:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...
This contains:
  • MIME type: image/png
  • Encoding: base64
  • Image data: The actual PNG image bytes

Download Examples

// After generating a QR code
const response = await fetch('https://jmpy.me/api/v1/qr-codes/generate', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    content_type: 'url',
    content_data: { url: 'https://example.com' }
  })
});

const data = await response.json();
const dataURL = data.data.qr_code_data;

// Method 1: Download as PNG
function downloadQRCode(dataUrl, filename = 'qrcode.png') {
  const link = document.createElement('a');
  link.href = dataUrl;
  link.download = filename;
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
}

downloadQRCode(dataURL, 'my-qr-code.png');

// Method 2: Display in an image element
const img = document.createElement('img');
img.src = dataURL;
document.body.appendChild(img);

// Method 3: Convert to Blob for custom handling
function dataURLtoBlob(dataUrl) {
  const arr = dataUrl.split(',');
  const mime = arr[0].match(/:(.*?);/)[1];
  const bstr = atob(arr[1]);
  let n = bstr.length;
  const u8arr = new Uint8Array(n);
  while (n--) {
    u8arr[n] = bstr.charCodeAt(n);
  }
  return new Blob([u8arr], { type: mime });
}

const blob = dataURLtoBlob(dataURL);
console.log('Blob size:', blob.size, 'bytes');

Converting to Different Formats

Since the API returns PNG format, you may want to convert to other formats client-side:
For true vector SVG, you would need to regenerate the QR code client-side. However, you can embed the PNG in an SVG container:
function pngToSvgWrapper(dataUrl, size = 300) {
  return `<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" 
     xmlns:xlink="http://www.w3.org/1999/xlink"
     width="${size}" height="${size}">
  <image xlink:href="${dataUrl}" width="${size}" height="${size}"/>
</svg>`;
}

// Usage
const svgContent = pngToSvgWrapper(dataURL, 400);

// Download as SVG
const svgBlob = new Blob([svgContent], { type: 'image/svg+xml' });
const svgUrl = URL.createObjectURL(svgBlob);

const link = document.createElement('a');
link.href = svgUrl;
link.download = 'qrcode.svg';
link.click();
from PIL import Image
from io import BytesIO
import base64

def convert_qr_to_jpeg(data_url, output_path, quality=90):
    # Extract base64 data
    _, encoded = data_url.split(',', 1)
    image_data = base64.b64decode(encoded)
    
    # Open as PIL Image
    image = Image.open(BytesIO(image_data))
    
    # Convert RGBA to RGB (JPEG doesn't support alpha)
    if image.mode == 'RGBA':
        background = Image.new('RGB', image.size, (255, 255, 255))
        background.paste(image, mask=image.split()[3])
        image = background
    
    # Save as JPEG
    image.save(output_path, 'JPEG', quality=quality)
    print(f"Saved to {output_path}")
// Resize QR code using Canvas API
function resizeQRCode(dataUrl, newSize) {
  return new Promise((resolve) => {
    const img = new Image();
    img.onload = () => {
      const canvas = document.createElement('canvas');
      canvas.width = newSize;
      canvas.height = newSize;
      
      const ctx = canvas.getContext('2d');
      ctx.imageSmoothingEnabled = false; // Keep sharp edges
      ctx.drawImage(img, 0, 0, newSize, newSize);
      
      resolve(canvas.toDataURL('image/png'));
    };
    img.src = dataUrl;
  });
}

// Usage
const resized = await resizeQRCode(dataURL, 1000);
downloadQRCode(resized, 'qrcode-large.png');

Best Practices

Choose the Right Size

Request a larger size in visual_settings.size (e.g., 500-1000px) to avoid quality loss when resizing.

Use High Error Correction

Set errorCorrectionLevel: 'H' if adding logos or printing at small sizes.

PNG for Digital Use

PNG format preserves sharp edges, ideal for screens and digital displays.

Consider JPEG for Print

Convert to JPEG with high quality (90%+) for print materials to reduce file size.