# EFQRCode Supported Animated QR Code Formats: GIF and APNG Generation Guide

> Learn to generate animated QR codes with EFQRCode in GIF and APNG formats. This guide covers essential methods for creating dynamic visual content.

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

---

**EFQRCode generates animated QR codes exclusively in GIF and APNG formats, controlled by the `EFAnimatedImageFormat` enum and exposed through dedicated `toGIFData()` and `toAPNGData()` methods.**

The EFQRCode library (efprefix/efqrcode) provides comprehensive QR code generation capabilities for Swift applications, including robust support for animated QR codes. When implementing dynamic QR codes that change over time, developers must choose between two specific animated image formats. This guide examines the supported animated QR code formats in EFQRCode, their technical implementations, and practical usage patterns.

## Supported Animated QR Code Formats in EFQRCode

EFQRCode supports exactly two animated image formats for QR code generation, defined in [`Source/Type/EFAnimatedImageFormat.swift`](https://github.com/efprefix/efqrcode/blob/main/Source/Type/EFAnimatedImageFormat.swift) at lines 66-70. The `EFAnimatedImageFormat` enum provides two distinct cases:

- **GIF** – `EFAnimatedImageFormat.gif` uses `UTType.gif` (iOS 14+) or `kUTTypeGIF` (pre-iOS 14) identifiers and produces files with the `.gif` extension.
- **APNG** – `EFAnimatedImageFormat.apng` uses `UTType.png` (iOS 14+) or `kUTTypePNG` (pre-iOS 14) identifiers and produces files with the `.apng` extension.

## How EFQRCode Implements Animated QR Code Generation

The generation logic resides in `Source/EFQRCode+Generator.swift`, where dedicated convenience methods wrap a common internal implementation.

### GIF Generation via toGIFData()

To generate animated GIF QR codes, EFQRCode exposes the `toGIFData()` method. Internally, this method calls `toAnimatedImage(format: .gif, …)` at lines 23-24 of `Source/EFQRCode+Generator.swift`. This approach ensures consistent parameter handling while targeting the GIF-specific rendering pipeline.

### APNG Generation via toAPNGData()

For animated PNG output, the `toAPNGData()` method provides equivalent functionality. This method invokes `toAnimatedImage(format: .apng, …)` at lines 65-66 of `Source/EFQRCode+Generator.swift`, routing the generation through the APNG codec for higher quality animation frames.

## Code Examples: Generating Animated QR Codes

The following Swift examples demonstrate practical implementation of both supported formats.

First, import the framework and initialize a generator with your target content:

```swift
import EFQRCode

// Initialize generator with URL or text payload
let generator = try EFQRCode.Generator("https://example.com")

```

Generate an animated GIF with explicit dimensions:

```swift
// Generate GIF data (200pt width default)
let gifData = try generator.toGIFData(width: 200)

// Write to filesystem
try gifData.write(to: URL(fileURLWithPath: "/tmp/animated.gif"))

```

Generate an animated APNG using alternative size specifications:

```swift
// Generate APNG from height parameter
let apngFromHeight = try generator.toAPNGData(height: 250)

// Or specify exact CGSize
let apngFromSize = try generator.toAPNGData(
    size: CGSize(width: 300, height: 300)
)

```

## Summary

EFQRCode provides comprehensive animated QR code generation through two distinct formats:

- **GIF support** implemented via `EFAnimatedImageFormat.gif` and exposed through `toGIFData()`, ideal for compatibility and smaller file sizes.
- **APNG support** implemented via `EFAnimatedImageFormat.apng` and exposed through `toAPNGData()`, offering higher visual quality and modern browser support.
- Both formats route through the internal `toAnimatedImage(format:...)` method in `Source/EFQRCode+Generator.swift`, ensuring consistent API behavior across output types.

## Frequently Asked Questions

### What animated formats does EFQRCode support?

EFQRCode exclusively supports **GIF** and **APNG** formats for animated QR code generation. These are defined in the `EFAnimatedImageFormat` enum located in [`Source/Type/EFAnimatedImageFormat.swift`](https://github.com/efprefix/efqrcode/blob/main/Source/Type/EFAnimatedImageFormat.swift) at lines 66-70. No other animation formats such as WebM or MP4 are currently implemented.

### How do I generate a GIF QR code with EFQRCode?

Use the `toGIFData()` method on your `EFQRCode.Generator` instance. This method internally calls `toAnimatedImage(format: .gif, …)` as implemented in `Source/EFQRCode+Generator.swift` at lines 23-24. You can specify width, height, or size parameters to control the output dimensions.

### What is the difference between GIF and APNG in EFQRCode?

**GIF** uses `EFAnimatedImageFormat.gif` with `UTType.gif` identifiers and produces `.gif` files, offering broad compatibility but limited to 256 colors. **APNG** uses `EFAnimatedImageFormat.apng` with `UTType.png` identifiers and produces `.apng` files, supporting full color depth and transparency but with potentially larger file sizes. Both formats route through the same internal generation pipeline via `toAnimatedImage(format:…)`.

### Where are the animated format definitions located in the source code?

The format definitions reside in [`Source/Type/EFAnimatedImageFormat.swift`](https://github.com/efprefix/efqrcode/blob/main/Source/Type/EFAnimatedImageFormat.swift), specifically at lines 66-70 where the `EFAnimatedImageFormat` enum declares the `gif` and `apng` cases. The generation methods implementing these formats are located in `Source/EFQRCode+Generator.swift`, with `toGIFData()` at lines 23-24 and `toAPNGData()` at lines 65-66.