qchenqizhi / QCropper

Image cropping/rotating/straightening library for iOS in Swift
MIT License
268 stars 51 forks source link

force image crop #13

Closed MichaelSamir47 closed 1 year ago

MichaelSamir47 commented 2 years ago

how to force cropping an image with aspect ratio (9:16)without free scaling?

qchenqizhi commented 2 years ago

You can set aspectRatioLocked = true and use AspectRatioSettable.setAspectRatio(_:) or AspectRatioSettable.setAspectRatioValue(_:)

MichaelSamir47 commented 2 years ago

Thanks

pallab-brainium commented 2 years ago

if I set

cropper.aspectRatioLocked = true and
cropper.setAspectRatio(.ratio(width: 8, height: 10))

then the app is crashing with this log in console

Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]. Layer: <CALayer:0x281880700; position = CGPoint (0 0); bounds = CGRect (0 0; 0 0); delegate = <QCropper.CropBox: 0x1016199d0; frame = (0 0; 0 0); layer = <CALayer: 0x281880700>>; sublayers = (<CALayer: 0x2818807e0>, <CALayer: 0x281880940>, <CALayer: 0x281880a60>, <CALayer: 0x281880b80>, <CALayer: 0x281880ca0>); allowsGroupOpacity = YES; borderWidth = 2; borderColor = <CGColor 0x283be1860> [<CGColorSpace 0x283ccc600> (kCGColorSpaceICCBased; kCGColorSpaceModelMonochrome; Generic Gray Gamma 2.2 Profile; extended range)] ( 1 1 ); backgroundColor = <CGColor 0x283bfa440> [<CGColorSpace 0x283ccc600> (kCGColorSpaceICCBased; kCGColorSpaceModelMonochrome; Generic Gray Gamma 2.2 Profile; extended range)] ( 0 0 )>'

AmyKao18 commented 2 years ago

Is aspectRatioLocked = true and use AspectRatioSettable.setAspectRatio(_:)or AspectRatioSettable.setAspectRatioValue(_:) set at CropperViewController.swift-func resetToDefaultLayout() ?