Git Product home page Git Product logo

efprefix / efqrcode Goto Github PK

View Code? Open in Web Editor NEW
4.6K 88.0 477.0 140.99 MB

A better way to operate QR Code in Swift, support iOS, macOS, watchOS and tvOS.

Home Page: https://efprefix.github.io/EFQRCode

License: MIT License

Ruby 1.01% Swift 93.56% Objective-C 3.28% Shell 1.26% C 0.88%
swift ios qrcode barcode barcode-scanner barcode-generator barcodes qrcode-generator qrcode-scanner qrcode-reader

efqrcode's Introduction

Compatible with all Platforms

EFQRCode is a lightweight, pure-Swift library for generating stylized QRCode images with watermark or icon, and for recognizing QRCode from images, inspired by qrcode. Based on CoreGraphics, CoreImage, and ImageIO, EFQRCode provides you a better way to handle QRCode in your app, no matter if it is on iOS, macOS, watchOS, and/or tvOS. You can integrate EFQRCode through CocoaPods, Carthage, and/or Swift Package Manager.

中文介绍

Examples

Demo Projects

App Store

You can click the App Store button below to download demo, support iOS, tvOS and watchOS:

You can also click the Mac App Store button below to download demo for macOS:

Compile Demo Manually

To run the example project manually, clone the repo, demos are in the 'Examples' folder, remember run command sh Startup.sh in terminal to get all dependencies first, then open EFQRCode.xcworkspace with Xcode and select the target you want, run.

Or you can run the following command in terminal:

git clone [email protected]:EFPrefix/EFQRCode.git; cd EFQRCode; sh Startup.sh; open 'EFQRCode.xcworkspace'

Requirements

Version Needs
1.x Xcode 8.0+
Swift 3.0+
iOS 8.0+ / macOS 10.11+ / tvOS 9.0+
4.x Xcode 9.0+
Swift 4.0+
iOS 8.0+ / macOS 10.11+ / tvOS 9.0+ / watchOS 2.0+
5.x Xcode 11.1+
Swift 5.0+
iOS 8.0+ / macOS 10.11+ / tvOS 9.0+ / watchOS 2.0+
6.x Xcode 12.0+
latest Swift
iOS 9.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+

Installation

CocoaPods

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

pod 'EFQRCode', '~> 6.2.2'

Then, run the following command:

$ pod install

Carthage

IMPORTANT: this workaround is necessary for Carthage to somewhat work in Xcode 12.

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 "EFPrefix/EFQRCode" ~> 6.2.2

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/EFPrefix/EFQRCode.git", .upToNextMinor(from: "6.2.2"))
]

Quick Start

1. Import EFQRCode

Import EFQRCode module where you want to use it:

import EFQRCode

2. Recognition

A String Array is returned as there might be several QR Codes in a single CGImage:

if let testImage = UIImage(named: "test.png")?.cgImage {
    let codes = EFQRCode.recognize(testImage)
    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.")
    }
}

3. Generation

Create QR Code image, basic usage:

Parameter Description
content REQUIRED, content of QR Code
size Width and height of image
backgroundColor Background color of QRCode
foregroundColor Foreground color of QRCode
watermark Background image of QRCode
if let image = EFQRCode.generate(
    for: "https://github.com/EFPrefix/EFQRCode",
    watermark: UIImage(named: "WWF")?.cgImage
) {
    print("Create QRCode image success \(image)")
} else {
    print("Create QRCode image failed!")
}

Result:

4. Generation from GIF

Use EFQRCode.generateGIF to create GIF QRCode.

Parameter Description
generator REQUIRED, an EFQRCodeGenerator instance with other settings
data REQUIRED, encoded input GIF
delay Output QRCode GIF delay, emitted means no change
loopCount Times looped in GIF, emitted means no change
if let qrCodeData = EFQRCode.generateGIF(
    using: generator, withWatermarkGIF: data
) {
    print("Create QRCode image success.")
} else {
    print("Create QRCode image failed!")
}

You can get more information from the demo, result will like this:

5. Next

Learn more from User Guide.

Recommendations

  1. Please select a high contrast foreground and background color combinations;
  2. To improve the definition of QRCode images, increase size, or scale up using magnification (instead);
  3. Magnification too high/size too large/contents too long 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
Objective-C https://github.com/z624821876/YSQRCode
Java https://github.com/SumiMakito/AwesomeQRCode
JavaScript https://github.com/SumiMakito/Awesome-qr.js
Kotlin https://github.com/SumiMakito/AwesomeQRCode-Kotlin
Python https://github.com/sylnsfar/qrcode

Contributors

This project exists thanks to all the people who already contributed to us. [Contribute]

Backers

If you think this project has brought you help, you can buy me a cup of coffee. If you like this project and are willing to provide further support for it's development, you can choose to become Backer in Open Collective. Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Other

Part of the pictures in the demo project and guide come from the internet. If there is any infringement of your legitimate rights and interests, please contact us to delete.

Contact

Email: [email protected]

License

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

efqrcode's People

Contributors

0xacdc avatar aiden-leong avatar apollozhu avatar basthomas avatar bertvh avatar bowmanonjupiter2 avatar chrs1885 avatar dependabot[bot] avatar eyrefree avatar giginet avatar haraguroicha avatar lemonnguyen avatar sumandeng avatar wacumov avatar wbcyclist avatar xdamman avatar zandor300 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

efqrcode's Issues

Cannot overload .generate() with all parameters

Xcode Version: 9.4.1
Swift Version: 4.1
Podfile depenency: pod "EFQRCode", '~> 4.2.2'

Problem: Unable to overload the code below with the following parameters:

  1. Magnification
  2. Mode
  3. InputCorrectionLevel
  4. Icon
  5. Transparency
  6. Binariazation
  7. Point Shape

Error given when trying to overload the generate method:

Incorrect argument label in call (have 'content:mode:foregroundColor:watermark:', expected 'content:size:foregroundColor:watermark:')

Code used:

if let tryImage = EFQRCode.generate(
            content: qrCodeString,
           // backgroundColor: Color.coral.value.cgColor,
            mode: EFQRCodeMode.binarization
            foregroundColor: Color.bondiBlue.value.cgColor,
            watermark: UIImage(named: "Logo-1.png")?.toCGImage()
            ) {
            print("Create QRCode image success: \(tryImage)")
            return UIImage(cgImage: tryImage)
        } else {
            print("Create QRCode image failed!")
            return nil
        }

Can you overload the generate method with more than just the base params? I also tried using the second option to initialize the code generator but got a different error. I do not want to throw multiple issues into one post but I felt that it was important to note why I am trying to overload the method rather than trying the other way.

Error when running pod install for 4.2.1

I am running xcode 9.2 using swift 4, I have this line in my pod file:

pod 'EFQRCode', '~> 4.2.1'

When running pod install, i get this :

image

But when i try to put just pod 'EFQRCode' , without the version, I can successfully run pod install without error, but the version is 4.0.0

Any ideas?

Thanks

Cross Platform Functionality

Probably a stupid question, but Is this library necessary to decode the QR code? Or can a normal QR code scanner read the data?

I would imagine a normal QR code scanner could read the data, but want to be sure before I implement it.

End goal: read the QR code in my Android App

CIFilter(name: "CIQRCodeGenerator") 方法崩溃

您好:我在使用EFQRCode时,在真机器iPhone X以上机型中:CIFilter(name: "CIQRCodeGenerator") 方法会崩溃,在真机器iPhone X以下,及iPhone 8 等,系统版本均为iOS13.1.3最新的,方法会无缘无故崩溃掉.请帮忙分析以下.谢谢

发现在iOS10以下的版本有兼容性问题

在iOS9.3的设备上,用这个库生成的二维码图片在微信中都无法识别
Alt text
很明显图片有问题
请问有人遇到过这种问题嘛?在iOS8上也有类似问题,我的调用代码如下:

Alt text

[Feature Request/Question] Support for watchOS or raw code matrix [[Bool]]

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • I have read the README.md, but there is no information I need.
  • I have searched in existing issues,
    • but did find a same one.

Feature/Question Description

Description

I would like to generate QRCode on watchOS. I am aware that CIFilter is not available on watchOS, so I ported qrcodejs to Swift here, which is able to generate raw code matrix in [[Bool]]. I wonder what would possibly be the most easy way to render that using EFQRCode. Thank you very much.

Other Comment

Although generating it on the phone and then transfer to the Apple Watch seems to be an acceptable approach. However, as Series 3 became more independent, there are cases where an iPhone is not available when in need.

generate can't be read by some qrcode reader(quickMark)

as title

code:

        if   let tryCGImage = EFQRCode.generate(
            content: "FCYKrciaHgodSKn3baKuPzas0k2PQJjI",
            size: EFIntSize(width: 240, height: 240)
            ) {
            let image = UIImage(cgImage: tryCGImage)
            qrcodeImageView?.image = image
            qrcodeImageView?.contentMode = .center
        }

screen shot 2017-06-08 at 14 10 56

艺术二维码

你好,我有一个问题想请教你一下。类似这样的二维码需要如何实现呢?我的想法是把码元分区,分成跟🌲、🏡大小相同的多个小区块,然后贴图替换。不知这样的方法是否可行。
image

QRCode oversize

使用1.2.4版本 使用example裡面的程式直接建立qrcode整個qrcode就跑掉了,只會顯示一個區塊而已
再麻煩看一下,

ios版本是9.3 iphone 6

screen shot 2017-05-10 at 21 58 59

Carthage update failure

Hi, I'm trying to install the framework via Carthage but i'm receiving the following error:

error: compiling for watchOS 2.0, but module 'swift_qrcodejs' has a minimum deployment target of watchOS 6.1:

my cartfile:
github "EFPrefix/EFQRCode" ~> 5.1.6

Command I'm using
Carthage update EFQRCode --platform watchOS

ASCII or other encoding options

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • I have read the README.md, but there is no information I need.
  • I have searched in existing issues, but did find a same one.

Issue Description

Description

Currently, any input string passed in to the generate QR code function is encoded as utf8 before being encoded in the QR code. Having an option to encode in ASCII or other encoding methods could allow larger texts to be encoded into smaller QR codes. Adding an argument to specify which text encoding method to use, which could default to utf8 would be a useful feature.

TxQR support

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • I have read the README.md, but there is no information I need.
  • I have searched in existing issues, but did find a same one.

Issue Description

New feature: TxQR animated QR code support

Description

TxQR is a type of three-dimensional QR code with time as the third dimension to encode more data.
Here is a list of items that EFQRCode could have

  • "beautifying" black-and-white TxQR codes using a static logo
  • Combining a TxQR code with a GIF to create a composite TxQR code

关于第一次生成耗时问题

//  使用
if let image = EFQRCode.generate(content: "280580947644881355") {
    let qrImage = UIImage(cgImage: image)
    imageView.image = qrImage
}

第一次 用时 1.9432099166660919
第二次用时 0.02680799999507144

请问有什么解决方法么?

Watch OS Compatibility

Hello !

In your READ.ME, you tell that your lib is compatible with Watch OS, but pod say that its not.

Is it still compatible ?

Diferent shape of Finder Pattern

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • I have read the README.md, but there is no information I need.
  • I have searched in existing issues, but did find a same one.

Is there a way to make a new shape of Finder Pattern, for example a circle instead a square?

Description

The Shape of I´m looking for is a circle.

qr-code

Reproduce

[The steps to reproduce this issue. What are the parameters, where did you put your code, etc.]

Other Comment

[Add anything else here]

Generated QR Code not match with CIImage generated

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • I have read the README.md, but there is no information I need.
  • I have searched in existing issues, but did find a same one.

Issue Description

Description

Inspect from func CIImage.generateQRCode(), the qrFilter.outputImage output correctly with following image

image

But func EFQRCodeGenerator.generate() result in following wrong image

image

Reproduce

none

Other Comment

change codes[indexY][indexX] to codes[indexX][indexY] 3 times in EFQRCodeGenerator.swift will resolve this issue

请问有没有oc版本的

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • I have read the README.md, but there is no information I need.
  • I have searched in existing issues, but did find a same one.

Issue Description

Description

[Tell us about the issue]

Reproduce

[The steps to reproduce this issue. What are the parameters, where did you put your code, etc.]

Other Comment

[Add anything else here]

Using EFQRCode images with normal QR code readers

Hey there,

Thanks for making this! Before I use it in my project, I was wondering since you can embed multiple codes in an image, how a standard QR code reader will read this, if at all.

I'm just putting one string in my QR code but I want other devices to be able to use they reader to read my codes. Will that work automatically for my use-case?

Documentation for watchOS Podspec missing

Issue Description

Using the podspec on WatchOS is undocumented

Description

Before this commit I was using the regular podcast spec on watchOS, and it worked.

Now I think I need to use pod 'EFQRCode/watchOS' but after pod installing that, there is no EFQRCode module installed.

More specifically, cocoapods seems to download and add EFQRCode as a module, but the project does not contain any source files. It looks like on watchOS it has been replaced by a dummy EFQRCode module.

Am I doing it wrong? Some documentation on the specifics of using this subspec on watchOS would be appreciated!

can't get image

    if let tryImage = EFQRCode.generate(content: "美少女战士",
                                        size: EFIntSize.init(width: 120, height: 120),
                                        backgroundColor: UIColor.orange.cgColor,
                                        foregroundColor: UIColor.yellow.cgColor,
                                        watermark: UIImage.init(named: "dog.png")?.toCGImage()) {
        
        imageView.image? = UIImage.init(cgImage: tryImage)
    }

above,It doesn't work.When I invoke like this,
if let tmpImage = EFQRCode.generate(content: "美少女战士",
watermark: UIImage.init(named: "dog.png")?.toCGImage()) {

        imageView.image = UIImage.init(cgImage: tmpImage)
    }

it works.why ?

Support data_matrix codes

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • I have read the README.md, but there is no information I need.
  • I have searched in existing issues, but did find a same one.

Issue Description

Description

Add support for scanning data_matrix style codes

Reproduce

Example code:

Raw text: |0015BC001E009B4D|E105EC0AF23A449FD66FA1DD9DE2F48C3631|
Raw bytes: 7d 82 91 e6 60 45 19 db 19 ae 5f 12 10 f3 1f ea 73 05 5a 7f 2d f9 34 1c 6b db 78 f6 6c f6 6d 17 78 0d fe 44 a6 a1 7d 81 a7 3e d4 6b
Barcode format: DATA_MATRIX

Other Comment

Looks like AVFoundation (iOS) supports this. Maybe it's possible to update EFQRCode to support it as well?

Fix Failing CI

As we can see on https://travis-ci.org/EFPrefix/EFQRCode, all the tests are failing due to missing simulators. From this StackOverflow answer, we can install the necessary simulators within the execution of each matrix configuration.

Note

There's a patch for iOS 9.3 simulator, which should now be executed for that configuration only, or completely removed if that's no longer necessary.

Addition of opportunities

Add please the ability to read QR Code using the camera, and the ability to create a QR Code contact, event, location, wi-fi.

oc项目怎么用

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • I have read the README.md, but there is no information I need.
  • I have searched in existing issues, but did find a same one.

Issue Description

Description

[Tell us about the issue]

Reproduce

[The steps to reproduce this issue. What are the parameters, where did you put your code, etc.]

Other Comment

[Add anything else here]

Compressed image will not be set as watermark

The judgement of isGIF in GeneratorController.swift Line 1079 will defend using the compressed image returned from selectedAlbumPhotosIncludingGifWithPHAssets, which seems a bug.

Carthage installation problem

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • [ X] I have read the README.md, but there is no information I need.
  • [ X] I have searched in existing issues, but did find a same one.

Issue Description

Description

Since version 5, the library cannot be installed using Carthage. Searching for the returned error on the internet, I got many results back but all solutions don't work. This is the returned error:

A shell task (/usr/bin/env git checkout --quiet 122809d12f0a3ed8323d2e6b3ddc7ec107a6afc9 (launched in /Users/project/Carthage/Checkouts/EFQRCode/Examples/3rd/SnapKit)) failed with exit code 128: fatal: reference is not a tree: 122809d12f0a3ed8323d2e6b3ddc7ec107a6afc9

Reproduce

Add this to the Cartfile and run carthage update:

github "EFPrefix/EFQRCode"

Pinning a version also doesn't work. The only thing that works for me is using version 4 from your personal github account:

github "EyreFree/EFQRCode" ~> 4.3.0

Other Comment

Tested on multiple devices, same result.

Thanks for this great library!

API

Thanks for sharing.

My suggestion is to make API a little bit more readable by adding couple of classes: Icon and Watermark.

Then, instead:

EFQRCode.generate(
    content: String, 
    inputCorrectionLevel: EFInputCorrectionLevel, 
    size: CGFloat, 
    magnification: UInt?, 
    backgroundColor: UIColor, 
    foregroundColor: UIColor, 
    icon: UIImage?, 
    iconSize: CGFloat?, 
    isIconColorful: Bool, 
    watermark: UIImage?, 
    watermarkMode: EFWatermarkMode, 
    isWatermarkColorful: Bool
)

It will be

EFQRCode.generate(
    content: String, 
    correction: EFInputCorrectionLevel, 
    size: CGFloat, 
    magnification: UInt?, 
    backgroundColor: UIColor, 
    foregroundColor: UIColor, 
    icon: Icon(image: UIImage, size: CGFloat, colorful: Bool)?, 
    watermark: Watermark(image: UIImage, mode: EFWatermarkMode, colorful: Bool)?
)

iOS 12 impossible to generate QR code.

I am using this lib to generate qr codes. But for iOS 12 it always fails to generate qr code.

After some investigation i found out that in iOS 12 filter CIFilter(name: "CIQRCodeGenerator") always return nil.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.