Skip to content

A simple controller that allows users to crop image using an arbitrary quadrilateral, and then return the croped image in a square rect.

License

Notifications You must be signed in to change notification settings

psven/SPImageCroperController

Repository files navigation

SPImageCroperController

A simple controller that allows users to crop image using an arbitrary quadrilateral, and then preview the tiled effect of the croped image in real time, and return the croped image in a square rect.

Screenshot

IMAGE

IMAGE

Features

  • Crop images by dragging the four angles of the selection box
  • Supports arbitrary quadrilateral
  • Adjust the croped image to a square by using CIPerspectiveCorrection

System Requirement

iOS 8.0 or above

Installation

Manual Installation

Simply copy the SPImageCroperController directory to your Xcode project.

Example

Using SPImageCroperController is very straightforward. Simply create a new instance passing the UIImage object you wish to crop, and then present it modally on the screen.

While SPImageCroperController prefers to be presented modally, it can also be pushed to a UINavigationController stack.

For a complete working example, check out the demo included in this repo.

Basic Implementation

You can implement SPImageCroperController just with one line code by using block:

SPImageCroperController *vc = [[SPImageCroperController alloc] initWithOriginalImage:image completion:^(SPImageCroperController *viewController, UIImage *cropedImage) {
    NSLog(@"invoke completionBlock");
} cancelBlock:^(SPImageCroperController *viewController) {
    NSLog(@"invoke cancelBlock");
}];
[self presentViewController:vc animated:YES completion:nil];
// [self.navigationController pushViewController:vc animated:YES];

Or using SPImageCroperControllerDelegate, which usage is similiar to UIImagePickerControllerDelegate:

SPImageCroperController *vc = [[SPImageCroperController alloc] init];
vc.originalImage = image;
vc.delegate = self;
[self presentViewController:vc animated:YES completion:nil];
- (void)imageCroperController:(SPImageCroperController *)viewController
        didFinishCropingImage:(UIImage *)image {
    NSLog(@"invoke -imageCroperController:didFinishCropingImage:");
}

- (void)imageCroperControllerDidCancel:(SPImageCroperController *)viewController {
    NSLog(@"invoke -imageCroperControllerDidCancel:");
}

License

SPImageCroperController is licensed under the MIT License, please see the LICENSE file.

About

A simple controller that allows users to crop image using an arbitrary quadrilateral, and then return the croped image in a square rect.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published