QRCode icon indicating copy to clipboard operation
QRCode copied to clipboard

Logo on the middle ?

Open Meta-Ben opened this issue 7 years ago • 2 comments

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.

Meta-Ben avatar Jun 27 '17 15:06 Meta-Ben

I have the same question about add logo in qrcode.

KC-218 avatar Jul 20 '17 09:07 KC-218

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).

hayashikun avatar Oct 27 '17 03:10 hayashikun