YPImagePicker icon indicating copy to clipboard operation
YPImagePicker copied to clipboard

onlySquare does not crop images to square

Open hanawat opened this issue 1 year ago • 4 comments

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 avatar Dec 15 '22 08:12 hanawat

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.

hanawat avatar Dec 15 '22 12:12 hanawat

+1

yunnnyunnn avatar Jan 15 '23 20:01 yunnnyunnn

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

Wahab-Khan avatar Apr 11 '23 20:04 Wahab-Khan

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

rinaldihno avatar Mar 03 '24 13:03 rinaldihno