Swift Ruby Objective-C
Latest commit 47b61d0 May 8, 2017 @EyreFree committed with Update README
Permalink
Failed to load latest commit information.
.github Add ISSUE_TEMPLATE.md Apr 12, 2017
EFQRCode.xcodeproj Update README Apr 29, 2017
EFQRCode.xcworkspace Setup tvOS Example Apr 23, 2017
Examples 1.2.4 Apr 23, 2017
Source Add test case Apr 25, 2017
Tests Fix CI Apr 25, 2017
.gitignore Develop (#7) Apr 16, 2017
.swift-version Fix Jan 24, 2017
.travis.yml Update README Apr 29, 2017
CHANGELOG.md 1.2.4 Apr 23, 2017
CONTRIBUTING.md 1.2.2 Apr 17, 2017
EFQRCode.podspec Update Apr 23, 2017
LICENSE Initial commit Jan 24, 2017
Package.swift Develop (#7) Apr 16, 2017
README.md Update README May 15, 2017
README_CN.md Update README May 15, 2017
USERGUIDE.md Update README May 15, 2017
USERGUIDE_CN.md Update README May 15, 2017
_config.yml Set theme jekyll-theme-cayman Apr 18, 2017
codecov.yml Update Apr 23, 2017

README.md

EFQRCode is a lightweight, pure-Swift library for generating pretty QRCode image with input watermark or icon and recognizing QRCode from image, it is based on CoreImage. This project is inspired by qrcode. It provides you a better way to operate QRCode in your app.

中文介绍

Overview

Demo

To run the example project, clone the repo, demos are in the 'Examples' folder.

Or you can run the following command in terminal:

git clone git@github.com:EyreFree/EFQRCode.git; cd EFQRCode/Examples/iOS; open 'iOS Example.xcodeproj'

Requirements

  • XCode 8.0+
  • Swift 3.0+
  • iOS 8.0+ / macOS 10.11+ / tvOS 9.0+

Installation

CocoaPods

EFQRCode is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "EFQRCode", '~> 1.2.4'

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate EFQRCode into your Xcode project using Carthage, specify it in your Cartfile:

github "EyreFree/EFQRCode" ~> 1.2.4

Run carthage update to build the framework and drag the built EFQRCode.framework into your Xcode project.

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding EFQRCode as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .Package(url: "https://github.com/EyreFree/EFQRCode.git", Version(1, 2, 4))
]

Quick Start

1. Import EFQRCode

Import EFQRCode module where you want to use it:

import EFQRCode

2. Recognition

Get QR Codes from CGImage, maybe there are several codes in a image, so it will return an array:

if let testImage = UIImage(named: "test.png")?.toCGImage() {
    if let tryCodes = EFQRCode.recognize(image: testImage) {
        if tryCodes.count > 0 {
            print("There are \(tryCodes.count) codes in testImage.")
            for (index, code) in tryCodes.enumerated() {
                print("The content of \(index) QR Code is: \(code).")
            }
        } else {
            print("There is no QR Codes in testImage.")
        }
    } else {
        print("Recognize failed, check your input image!")
    }
}

3. Generation

Create QR Code image, quick usage:

// Common parameters:
//                         content: Content of QR Code
// inputCorrectionLevel (Optional): error-tolerant rate
//                                  L 7%
//                                  M 15%
//                                  Q 25%
//                                  H 30%(Default)
//                 size (Optional): Width and height of image
//        magnification (Optional): Magnification of QRCode compare with the minimum size
//                                  (Parameter size will be ignored if magnification is not nil)
//      backgroundColor (Optional): Background color of QRCode
//      foregroundColor (Optional): Foreground color of QRCode
//                 icon (Optional): Icon in the middle of QR Code Image and it's setting
//            watermark (Optional): Watermark background image and it's setting
//                extra (Optional): Extra parameters
if let tryImage = EFQRCode.generate(
    content: "https://github.com/EyreFree/EFQRCode",
    magnification: EFIntSize(width: 9, height: 9),
    watermark: EFWatermark(image: UIImage(named: "WWF")?.toCGImage(), mode: .scaleAspectFill, isColorful: false)
) {
    print("Create QRCode image success: \(tryImage)")
} else {
    print("Create QRCode image failed!")
}

Result:

Learn more from User Guide.

Todo

  • Support GIF
  • Support more styles

PS

  1. Please select a high contrast foreground and background color combinations;
  2. You should use magnification instead of size if you want to improve the definition of QRCode image, you can also increase the value of them;
  3. Magnification too high/Size too long/Content too much may cause failure;
  4. It is recommended to test the QRCode image before put it into use;
  5. You can contact me if there is any problem, both Issue and Pull request are welcome.

PS of PS: I wish you can click the Star button if this tool is useful for you, thanks, QAQ...

Other Platforms/Languages

Platforms/Languages Link
Python https://github.com/sylnsfar/qrcode
Java https://github.com/SumiMakito/AwesomeQRCode
JavaScript https://github.com/SumiMakito/Awesome-qr.js

Contact

Email: eyrefree@eyrefree.org
Weibo: @EyreFree
Twitter: @EyreFree777

License

EFQRCode is available under the MIT license. See the LICENSE file for more info.