Transform
Our transform tool unifies cropping, flipping and rotation operations in one feature. The PhotoEditor SDK holds various preset crop ratios (e.g. 16:9) that can easily be complemented by any crop ratio you deem necessary.
The tool is implemented in the TransformToolController
class and can be customized using the TransformToolControllerOptions
as described in the configuration section. By modifying these options, you may customize the available transform actions and crop aspect ratios by adding or removing CropAspect
and TransformAction
objects from or to the corresponding arrays. All sliders and buttons can be customized as well. In order to disable free cropping and force the use of one of the available aspect ratios, set the allowFreeCrop
property to false
.
In order to force your users to crop their image to one of the available crop ratios, you can use the PhotoEditViewControllerOptions
to configure the editor accordingly:
let configuration = Configuration { builder inbuilder.configureTransformToolController { options inoptions.allowFreeCrop = falseoptions.allowedCropRatios = [CropAspect(width: 1, height: 1, localizedName: "Square", rotatable: false),CropAspect(width: 3, height: 2, localizedName: "Landscape", rotatable: false),CropAspect(width: 2, height: 3, localizedName: "Portrait", rotatable: false)]}builder.configurePhotoEditorViewController { options inoptions.forceCropMode = true}}let sampleImage = UIImage(named: "sample_image")!let photo = Photo(image: sampleImage)let photoEditViewController = PhotoEditViewController(photoAsset: photo, configuration: configuration)
To let your users crop their image to specific aspect ratios used by social networks (e.g. Facebook, Twitter, Instagram, Flickr), you simply have to set the desired aspect ratio and name it accordingly (setting the aspect ratio will not affect the resolution of the image):
let configuration = Configuration { builder inbuilder.configureTransformToolController { options inoptions.allowFreeCrop = trueoptions.allowedCropRatios = [CropAspect(width: 3, height: 4, localizedName: "Facebook Post", rotatable: false),CropAspect(width: 828, height: 315, localizedName: "Facebook Cover", rotatable: false),CropAspect(width: 2, height: 3, localizedName: "Twitter Post", rotatable: false),CropAspect(width: 1, height: 1, localizedName: "Linkedin Post", rotatable: false),CropAspect(width: 1, height: 1, localizedName: "Instagram Post", rotatable: false)]}}let sampleImage = UIImage(named: "sample_image")!let photo = Photo(image: sampleImage)let photoEditViewController = PhotoEditViewController(photoAsset: photo, configuration: configuration)