# EFQRCode QR Code Generation Formats: PNG, SVG, GIF, PDF, Video, and More

> Explore EFQRCode formats: PNG, SVG, GIF, PDF, MOV, MP4, and more. Generate versatile QR codes for any project with this powerful library.

- Repository: [EFPrefix/efqrcode](https://github.com/efprefix/efqrcode)
- Tags: api-reference
- Published: 2026-03-01

---

**EFQRCode supports twelve distinct QR code generation formats across four categories: static images (PNG, JPEG, SVG), animated images (GIF, APNG), documents (PDF), and video formats (MOV, MP4, M4V), plus native UIKit/AppKit image objects.**

EFQRCode is a Swift library for generating and recognizing QR codes in iOS, macOS, and watchOS applications. Understanding the available **QR code generation formats** helps you choose the right output method for your specific use case, whether you need vector graphics for print scalability, raster images for UI display, or video formats for animated QR codes.

## Supported QR Code Output Formats

The `EFQRCode.Generator` class in `EFQRCode+Generator.swift` defines the complete matrix of output capabilities. The implementation groups formats into four functional categories, with specific API methods for each type.

### Static Raster Images: PNG and JPEG

For standard bitmap output, EFQRCode provides **PNG** and **JPEG** generation with compression quality control.

- **`toPNGData(width:height:insets:)`** – Returns lossless PNG `Data` (lines 322‑335 in `EFQRCode+Generator.swift`)
- **`toJPEGData(width:height:insets:compressionQuality:)`** – Returns JPEG `Data` with configurable compression quality 0.0‑1.0 (lines 370‑386)

Both methods accept `width`, `height`, and `insets` parameters to control the final render size and padding.

### Vector Graphics: SVG

For resolution‑independent output suitable for print or web, EFQRCode generates **SVG** vector paths.

- **`toSVG()`** – Returns a `String` containing the complete SVG markup (lines 225‑232 in `EFQRCode+Generator.swift`)

The SVG output encodes the QR modules as vector rectangles, allowing infinite scaling without pixelation.

### Animated Images: GIF and APNG

EFQRCode supports **animated QR codes** that cycle through different styles or colors. The generator produces two animated image formats:

- **`toGIFData(width:height:insets:)`** – Returns animated GIF `Data` (lines 95‑101)
- **`toAPNGData(width:height:insets:)`** – Returns animated PNG `Data` (lines 127‑133)

These methods rely on the `EFAnimatedImageFormat` enum defined in [`Source/Type/EFAnimatedImageFormat.swift`](https://github.com/efprefix/efqrcode/blob/main/Source/Type/EFAnimatedImageFormat.swift), which maps format types to their CoreGraphics Uniform Type Identifiers.

### Document Format: PDF

For document workflows and print‑ready output, EFQRCode generates **PDF** documents containing the QR code as a vector object.

- **`toPDFData(width:height:insets:)`** – Returns PDF `Data` suitable for saving or sharing (lines 572‑595 in `EFQRCode+Generator.swift`)

The PDF output maintains vector quality, making it ideal for high‑resolution printing on physical media.

### Video Formats: MOV, MP4, and M4V

For applications requiring video‑based QR codes (such as animated watermarks or video overlays), EFQRCode supports three video containers:

- **`toMovData(width:height:insets:)`** – Apple QuickTime format (lines 51‑57)
- **`toMp4Data(width:height:insets:)`** – Cross‑platform MPEG‑4 format (lines 71‑77)
- **`toM4vData(width:height:insets:)`** – Apple‑specific MPEG‑4 variant (lines 65‑71)

These methods utilize the `EFVideoFormat` enum in [`Source/Type/EFVideoFormat.swift`](https://github.com/efprefix/efqrcode/blob/main/Source/Type/EFVideoFormat.swift) to map formats to their AVFoundation file type identifiers.

### Native Platform Images: UIImage and NSImage

For direct UI integration without intermediate file I/O, EFQRCode provides platform‑specific image objects:

- **`toImage(width:)`** or **`toImage(height:)`** – Returns `UIImage` on iOS/tvOS or `NSImage` on macOS

These methods essentially wrap the PNG generation pipeline, returning rasterized image objects ready for display in `UIImageView` or `NSImageView`.

## Implementation Details and Source Files

The format support matrix is implemented across several key files in the EFQRCode repository:

- **`Source/EFQRCode+Generator.swift`** – Contains the core `Generator` class with all `toPNGData`, `toSVG`, `toGIFData`, `toPDFData`, and video format methods (lines 78‑84 define the output format groups).
- **[`Source/Type/EFAnimatedImageFormat.swift`](https://github.com/efprefix/efqrcode/blob/main/Source/Type/EFAnimatedImageFormat.swift)** – Defines the `EFAnimatedImageFormat` enum mapping GIF and APNG to their Uniform Type Identifiers.
- **[`Source/Type/EFVideoFormat.swift`](https://github.com/efprefix/efqrcode/blob/main/Source/Type/EFVideoFormat.swift)** – Defines the `EFVideoFormat` enum mapping MOV, MP4, and M4V to AVFoundation file types.
- **[`Source/EFQRCode.swift`](https://github.com/efprefix/efqrcode/blob/main/Source/EFQRCode.swift)** – Public entry point housing the `Generator` nested type.

## Code Examples for Each Format

The following Swift examples demonstrate how to generate QR codes in each supported format. All examples assume you have initialized a `EFQRCode.Generator` instance:

```swift
import EFQRCode

// Initialize generator
let generator = try EFQRCode.Generator("https://example.com")

```

### Generate PNG Data

```swift
let pngData = try generator.toPNGData(width: 300)
try pngData.write(to: URL(fileURLWithPath: "/tmp/qrcode.png"))

```

### Generate JPEG with Compression Quality

```swift
let jpegData = try generator.toJPEGData(
    width: 300,
    compressionQuality: 0.85
)
try jpegData.write(to: URL(fileURLWithPath: "/tmp/qrcode.jpg"))

```

### Generate SVG String

```swift
let svgString = try generator.toSVG()
try svgString.write(
    to: URL(fileURLWithPath: "/tmp/qrcode.svg"),
    atomically: true,
    encoding: .utf8
)

```

### Generate Animated GIF

```swift
let gifData = try generator.toGIFData(width: 300)
try gifData.write(to: URL(fileURLWithPath: "/tmp/qrcode.gif"))

```

### Generate Animated PNG (APNG)

```swift
let apngData = try generator.toAPNGData(width: 300)
try apngData.write(to: URL(fileURLWithPath: "/tmp/qrcode.apng"))

```

### Generate PDF Document

```swift
let pdfData = try generator.toPDFData(width: 300)
try pdfData.write(to: URL(fileURLWithPath: "/tmp/qrcode.pdf"))

```

### Generate Video Files

```swift
// QuickTime format
let movData = try generator.toMovData(width: 300)
try movData.write(to: URL(fileURLWithPath: "/tmp/qrcode.mov"))

// MPEG-4 format
let mp4Data = try generator.toMp4Data(width: 300)
try mp4Data.write(to: URL(fileURLWithPath: "/tmp/qrcode.mp4"))

// Apple MPEG-4 variant
let m4vData = try generator.toM4vData(width: 300)
try m4vData.write(to: URL(fileURLWithPath: "/tmp/qrcode.m4v"))

```

### Direct UI Image Generation

```swift
#if canImport(UIKit)
let uiImage = try generator.toImage(width: 300)  // UIImage
#endif

#if canImport(AppKit)
let nsImage = try generator.toImage(width: 300)  // NSImage
#endif

```

## Summary

EFQRCode provides comprehensive **QR code generation format** support through the `EFQRCode.Generator` class:

- **Static raster images** via `toPNGData` and `toJPEGData` with configurable compression and dimensions.
- **Vector graphics** via `toSVG` for resolution-independent output.
- **Animated formats** via `toGIFData` and `toAPNGData` for dynamic QR codes.
- **Document output** via `toPDFData` for print-ready vector documents.
- **Video containers** via `toMovData`, `toMp4Data`, and `toM4vData` for video-based codes.
- **Native platform objects** via `toImage` for direct UI integration without file I/O.

All format methods are implemented in `Source/EFQRCode+Generator.swift`, with supporting type definitions in [`EFAnimatedImageFormat.swift`](https://github.com/efprefix/efqrcode/blob/main/EFAnimatedImageFormat.swift) and [`EFVideoFormat.swift`](https://github.com/efprefix/efqrcode/blob/main/EFVideoFormat.swift).

## Frequently Asked Questions

### Does EFQRCode support SVG output for QR codes?

Yes, EFQRCode generates resolution-independent **SVG** vector graphics through the `toSVG()` method defined in `Source/EFQRCode+Generator.swift` (lines 225‑232). This returns a `String` containing the complete SVG markup, which you can write to disk or embed directly in web content without pixelation at any scale.

### How do I generate animated QR codes with EFQRCode?

EFQRCode supports **animated QR codes** in both GIF and APNG formats. Use `toGIFData(width:height:insets:)` for GIF output or `toAPNGData(width:height:insets:)` for Animated PNG. These methods are located in `Source/EFQRCode+Generator.swift` (lines 95‑101 and 127‑133) and rely on the `EFAnimatedImageFormat` enum to handle the underlying CoreGraphics encoding.

### What video formats does EFQRCode support for QR code generation?

EFQRCode can export QR codes as video files in three container formats: **MOV** (QuickTime), **MP4** (MPEG‑4), and **M4V** (Apple MPEG‑4). The corresponding methods are `toMovData`, `toMp4Data`, and `toM4vData`, implemented in `Source/EFQRCode+Generator.swift`. These methods utilize the `EFVideoFormat` enum to map formats to their AVFoundation file type identifiers.

### Can I generate a UIImage directly without creating a file?

Yes, the `toImage(width:)` and `toImage(height:)` methods return native platform image objects—`UIImage` on iOS/tvOS or `NSImage` on macOS—without writing to disk. These methods essentially wrap the PNG generation pipeline and are useful for displaying QR codes directly in image views or sharing via UIActivityViewController without intermediate file I/O operations.