fix: apply targetWidth and targetHeight when picking images from gallery - #16
fix: apply targetWidth and targetHeight when picking images from gallery#16andredestro wants to merge 1 commit into
Conversation
9ee5e6b to
7e498d8
Compare
7e498d8 to
f6d1acf
Compare
OS-pedrogustavobilro
left a comment
There was a problem hiding this comment.
I tested and it seems to now resize the image when passing targetWidth / targetHeight from gallery, but noticed some things that may still need to be addressed.
| let resized = image.resizeTo(CGSize(size: size)) ?? image | ||
| let quality = CGFloat(IONCAMRTakePhotoOptions.ThumbnailDefaultConfigurations.quality) / 100 | ||
| guard let data = resized.jpegData(compressionQuality: quality)?.base64EncodedString() | ||
| else { throw IONCAMRError.imageNotFound } | ||
| finalImage = resized | ||
| imageData = data |
There was a problem hiding this comment.
Wondering if this should be applied to only the thumbnail or also the image URI being returned (i.e. save the image to a new URI, possibly cache, and return that instead)?
Also, targetWidth / targetHeight doesn't seem to get applied if we pass something in "editable". Possibly it goes through a different flow?
| let finalImage: UIImage | ||
| let imageData: String | ||
| if let size = targetSize { | ||
| let resized = image.resizeTo(CGSize(size: size)) ?? image |
There was a problem hiding this comment.
I thought the resize would be to the exact dimensions, but it seems that it does it an way that makes it such that it can switch up the dimensions. I think the capacitor example app doesn't show the thumbnail so it makes it hard to tell (related to my other comment), but this logic probably comes from the old cordova plugin / native library, but just checking if it's by design.
// Figure out what our orientation is, and use that to form the rectangle
let newSize = if widthRatio > heightRatio {
CGSize(width: sourceImage.size.width * heightRatio, height: sourceImage.size.height * heightRatio)
} else {
CGSize(width: sourceImage.size.width * widthRatio, height: sourceImage.size.height * widthRatio)
}
Because if it is, maybe we need to see what Android should do, and update the docs on what targetWidth / targetHeight are meant to be?
Summary
targetWidthandtargetHeightbeing silently ignored when picking images from the gallery.size: IONCAMRSize?toIONCAMRGalleryOptions, decoded from thetargetWidth/targetHeightkeys (both must be present; if only one is provided, the size is ignored)targetSizethroughIONCAMRGalleryBehaviourdown toIONCAMRPhotoLibraryServicetargetSizeis set, the selected image is resized viaresizeTo(_:)and compressed with the default thumbnail quality before being returned as base64; otherwise the existingpictureThumbnailData()path is used