YPImagePicker
YPImagePicker copied to clipboard
onlySquare does not crop images to square
Describe the bug
Enabling onlySquare
in YPImagePickerConfiguration
(YPConfigLibrary
) does not force a square image to be selected.
To Reproduce
Use YPImagePicker
as follows:
The setting is onlySquare
enabled, so the output image size should be square.
var configuration = YPImagePickerConfiguration()
configuration.library.onlySquare = true
let picker = YPImagePicker(configuration: configuration)
picker.didFinishPicking(completion: { [unowned picker] items, isCancelled in
defer { picker.dismiss(animated: true) }
guard !isCancelled else { return }
items.forEach({ item in
switch item {
case .photo(let photo):
// Image size not cropped to square.
// image size: (4032.0, 3024.0)
print("image size:", photo.image.size)
default:
break
}
})
})
present(picker, animated: true)
Expected behavior
If onlySquare
is enabled in YPImagePickerConfiguration
(YPConfigLibrary
), the image will be cropped to square.
Screenshots If the user zooms in on this screen and crops the image to a square, a square image will be created. It is a strange behavior to have a non-square crop on this screen.
Environment (please complete the following information):
- Device: iPhone14 Pro
- OS: iOS16.1
- Xcode Version: 14.1
- Swift Version 5.3
Installation Type
- Cocoapods
I found that the following values do not update unless scrollViewDidEndZooming
is called.
https://github.com/Yummypets/YPImagePicker/blob/5.2.1/Source/Pages/Gallery/YPAssetZoomableView.swift#L25
And the fix was already in the master branch. https://github.com/Yummypets/YPImagePicker/pull/724
However, this fix is not enough, the squaredZoomScale
is calculated immediately, but the display is still not square.
So I have created the following PR.
https://github.com/Yummypets/YPImagePicker/pull/777
If there are no problems, I would like you to merge it into master and release cocoapods.
+1
When I select multiple images it only returns the first image as a square ... all others are original images from the library.
Any update about this issue in multiple images ? Is there a workaround that I could do in didFinishPicking ? Thanks for help