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
Added base64 to UIImageExtensions #363
Conversation
|
||
/// EZSE: Returns base64 string | ||
var base64: String { | ||
return UIImageJPEGRepresentation(self, 1.0)!.base64EncodedString() |
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.
Is it possible to test this ?
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.
We could download an image with a link and then get the base 64 from a website like this: https://www.base64-image.de/
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.
I would avoid network IO if I could. Lets keep a downloaded image in some testdata folder or something of that order. Or just test on charizard.png.
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.
@Khalian couldn't get the image to work. Keep getting nil
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.
@lfarah Which image did you test it on ?
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.
The charizard one. Can you try to do it?
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.
Yes I was able to get it to work. My prototype code was :
public func testImageBase64() {
let image = UIImage(contentsOfFile: "/workplace/arunavs/third_party/EZSwiftExtensions/charizard.png")
print(image?.base64)
}
It gave a non nil base 64 encoded string.
Can you write a test(with the path formatted as a relative path) to assert that the output is not nil and also its of base 64 format (do we have an extension/foundation API for that?). I will approve this after that.
Generated by 🚫 Danger |
@Khalian I have no idea why the test is not working. Converted the |
You can avoid the merge commits by rebasing the branch locally and force pushing onto the remote branch (never force push on mainline). |
I can clean it later... Just wanna get this test working |
@vsouza can you help? |
As long as you get some base64 string, IMO its good enough a test. |
@Khalian what do you think? |
let dataImage = try? Data(contentsOf: imageURL!) | ||
let image = UIImage(data: dataImage!) | ||
|
||
XCTAssertNotNil(image!.base64) |
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.
Lets add a stronger check here:-
if let decodedData = NSData(base64EncodedString: image!.base64, options: nil) {
// Pass test case
} else {
// Fail test case.
}
Dont forget to squash the commits into one. |
@piv199 @goktugyil What do you guys think ? |
@lfarah Can you replay your changes on existing master ? |
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.
I don't really understand the code here but nothing looks weird so
@goktugyil Its a base64 conversion of an image. Traditionally base64 conversions for different inputs (including binary encodings) are used to transmit information over the HTTP protocol. |
I understand that part :D |
@goktugyil Basically base64 is the most used way to do image upload. I use it all the time on my freelance projects. There are a lot of changes because testing it was really shitty |
fixes #355
Checklist