Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logo on the middle ? #50

Open
Meta-Ben opened this issue Jun 27, 2017 · 2 comments
Open

Logo on the middle ? #50

Meta-Ben opened this issue Jun 27, 2017 · 2 comments

Comments

@Meta-Ben
Copy link

Hello,

This a very nice work, but I have one question, it is possible to put a logo in the middle of the QR Code ?

Thank's in advance.

@KC-218
Copy link

KC-218 commented Jul 20, 2017

I have the same question about add logo in qrcode.

@hayashikun
Copy link

It is possible by using UIGraphicsImageContext

private func generateQRCode(str: String) -> UIImage? {
        guard var qrCode = QRCode(str) else {
            return nil
        }
        qrCode.errorCorrection = .High
        guard let qrImage = qrCode.image, let logoImage = UIImage(named: "logo") else {
            return nil
        }

        let logoWidth = qrImage.size.width / 4
        UIGraphicsBeginImageContextWithOptions(qrImage.size, false, 0)
        qrImage.draw(in: CGRect(origin: .zero, size: qrImage.size))
        logoImage.draw(in: CGRect(x: (qrImage.size.width - logoWidth) / 2, y: (qrImage.size.width - logoWidth) / 2,
                                  width: logoWidth, height: logoWidth))
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()

        return image
    }

I don't know this is the best way.
I want function to put image like QRCode#put(image: UIImage).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants