EFQRCode Documentation

repository·main·Indexed 26 days ago

https://github.com/efprefix/efqrcode

A lightweight, pure-Swift library for generating stylized static and animated QR code images with watermark support, and recognizing QR codes from images. Compatible with iOS, macOS, watchOS, tvOS, and visionOS. Supports various export formats including PNG, JPEG, PDF, GIF, APNG, SVG, and MP4.

Tokens
962
Snippets
5
Records
7
Agent score
39%

What's inside EFQRCode

  1. Generate a static QR Code image

    main

    Use EFQRCode.Generator to create a stylized QR code. You can pass a URL or string and apply a style using an image as a watermark or icon.

    import EFQRCode
    
    let generator = try? EFQRCode.Generator("https://github.com/EFPrefix/EFQRCode", style: .image( 
        params: .init(image: .init(image: .static(image: .static(image: UIImage(named: "WWF")?.cgImage!)!, allowTransparent: true)))
    ))
    
    if let image = try? generator?.toImage(width: 180).cgImage {
        print("Create QRCode image success \(image)")
    } else {
        print("Create QRCode image failed!")
    }
  2. Generate an animated QR Code (GIF)

    main

    Create dynamic QR codes by passing a sequence of CGImage objects and their corresponding delays to the generator. Use toGIFData(width:) to export the result.

    import EFQRCode
    
    let generator = try? EFQRCode.Generator("https://github.com/EFPrefix/EFQRCode", style: .image(
        params: .init(image: .init(image: .animated(images: cgImages, imageDelays: cgImageDelays)))
    ))
    
    if let imageData = try? generator?.toGIFData(width: 512) {
        print("Create QRCode image success \(imageData)")
    } else {
        print("Create QRCode image failed!")
    }
  3. Recognize QR Codes from an image

    main

    Use EFQRCode.Recognizer to extract QR code content from a CGImage. The recognize() method returns an array of strings, as a single image may contain multiple QR codes.

    import EFQRCode
    
    if let testImage = UIImage(named: "test.png")?.cgImage {
        let codes = EFQRCode.Recognizer(image: testImage).recognize()
        if !codes.isEmpty {
            print("There are \(codes.count) codes")
            for (index, code) in codes.enumerated() {
                print("The content of QR Code \(index) is \(code).")
            }
        } else {
            print("There is no QR Codes in testImage.")
        }
    }