Skip to content
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

onlySquare does not crop images to square #776

Open
hanawat opened this issue Dec 15, 2022 · 4 comments
Open

onlySquare does not crop images to square #776

hanawat opened this issue Dec 15, 2022 · 4 comments

Comments

@hanawat
Copy link

hanawat commented Dec 15, 2022

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.
スクリーンショット 2022-12-15 17 10 25 スクリーンショット 2022-12-15 17 30 17

Environment (please complete the following information):

  • Device: iPhone14 Pro
  • OS: iOS16.1
  • Xcode Version: 14.1
  • Swift Version 5.3

Installation Type

  • Cocoapods
@hanawat
Copy link
Author

hanawat commented Dec 15, 2022

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.
#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.
#777

If there are no problems, I would like you to merge it into master and release cocoapods.

@yunnnyunnn
Copy link

+1

@Wahab-Khan
Copy link

When I select multiple images it only returns the first image as a square ... all others are original images from the library.

@rinaldihno
Copy link

Any update about this issue in multiple images ? Is there a workaround that I could do in didFinishPicking ?
Thanks for help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants