-
Notifications
You must be signed in to change notification settings - Fork 121
[Scan to Pay]Add logo to the Scan to Pay QR Code #9823
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
97b116f
Add logo to the Scan to Pay QR Code
toupper 72b2b73
Add empty lines for better readability
toupper 0d17ba5
Add format, better naming, and comments
toupper 57d7200
Add Release note
toupper 2d13b6d
Merge branch 'trunk' into issue/9748-add-woo-logo-qr-code-scan-to-pay
toupper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
WooFoundation/WooFoundation/Extensions/CIImage+ImageCombination.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import CoreImage.CIFilterBuiltins | ||
|
|
||
| extension CIImage { | ||
| /// Combines the current image with the given image centered. | ||
| /// | ||
| func combined(with image: CIImage) -> CIImage? { | ||
| guard let combinedFilter = CIFilter(name: "CISourceOverCompositing") else { | ||
| return nil | ||
| } | ||
|
|
||
| let centerTransform = CGAffineTransform(translationX: extent.midX - (image.extent.size.width / 2), y: extent.midY - (image.extent.size.height / 2)) | ||
| combinedFilter.setValue(image.transformed(by: centerTransform), forKey: "inputImage") | ||
| combinedFilter.setValue(self, forKey: "inputBackgroundImage") | ||
|
|
||
| return combinedFilter.outputImage | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
WooFoundation/WooFoundation/Extensions/UIImage+Background.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import UIKit | ||
|
|
||
| public extension UIImage { | ||
| /// Adds a background color to the given UIImage, setting also whether it should be opaque or not | ||
| /// | ||
| func withBackground(color: UIColor, opaque: Bool = true) -> UIImage { | ||
| UIGraphicsBeginImageContextWithOptions(size, opaque, scale) | ||
|
|
||
| guard let ctx = UIGraphicsGetCurrentContext(), | ||
| let image = cgImage else { | ||
| return self | ||
| } | ||
|
|
||
| defer { UIGraphicsEndImageContext() } | ||
|
|
||
| let rect = CGRect(origin: .zero, size: size) | ||
| ctx.setFillColor(color.cgColor) | ||
| ctx.fill(rect) | ||
| ctx.concatenate(CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: size.height)) | ||
| ctx.draw(image, in: rect) | ||
|
|
||
| return UIGraphicsGetImageFromCurrentImageContext() ?? self | ||
| } | ||
| } | ||
39 changes: 39 additions & 0 deletions
39
WooFoundation/WooFoundation/Extensions/URL+QRCodeGeneration.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import Foundation | ||
| import UIKit | ||
|
|
||
| public extension URL { | ||
| /// Returns a black and white QR UIImage code for this URL. | ||
| /// | ||
| func generateQRCode() -> UIImage? { | ||
| guard let outputImage = generateQRCodeCIImage(), | ||
| let cgImage = CIContext().createCGImage(outputImage, from: outputImage.extent) else { | ||
| return nil | ||
| } | ||
|
|
||
| return UIImage(cgImage: cgImage) | ||
| } | ||
|
|
||
|
|
||
| /// Returns a black and white QR code for this URL, adding the passed image centered. | ||
| /// | ||
| func generateQRCode(combinedWith image: UIImage) -> UIImage? { | ||
| guard let outputImage = generateQRCodeCIImage(), | ||
| let cgLogoImage = image.cgImage, | ||
| let combinedImage = outputImage.combined(with: CIImage(cgImage: cgLogoImage)), | ||
| let cgImage = CIContext().createCGImage(combinedImage, from: combinedImage.extent) else { | ||
| return nil | ||
| } | ||
|
|
||
| return UIImage(cgImage: cgImage) | ||
| } | ||
|
|
||
| /// Returns a black and white QR CIImage code for this URL. | ||
| /// | ||
| private func generateQRCodeCIImage() -> CIImage? { | ||
| let filter = CIFilter.qrCodeGenerator() | ||
| filter.message = Data(absoluteString.utf8) | ||
|
|
||
| let qrTransform = CGAffineTransform(scaleX: 12, y: 12) | ||
| return filter.outputImage?.transformed(by: qrTransform) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot happening here, so I think we could improve it by:
ctxtocurrentGraphicsContextWhat do you think? I tested the changes to
CGAfflineTransformand we get the same result , unless there's any other concern I've missed it seems that, from Apple docs, we shouldn't access this property directly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comment! I added some of the suggestions here in 0d17ba5 Some parts of the code were self-explanatory and didn't need comments, but some others were indeed abstruse