Giter VIP home page Giter VIP logo

uiimagecropper's Introduction

UIImageCropper

Simple Image cropper for UIImagePickerController with customisable crop aspect ratio. Made purely with Swift 4!

Replaces the iOS "crop only to square" functionality. Easy few line setup with delegate method/s.

Requirements

  • iOS10+
  • Xcode 9.2+
  • Swift 4

Install

UIImageCropper is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'UIImageCropper'

(or add UIImageCropper folder to your project)

Usage

Import the pod

import UIImageCropper

Create instanses of UIImageCropper and UIImagePickerController (optional, if cropping existing UIImage)

UIImageCropper can take cropRatio as parameter. Default ratio is 1 (square).

let picker = UIImagePickerController()
let cropper = UIImageCropper(cropRatio: 2/3)

Setup UIImageCropper

cropper.picker = picker
cropper.delegate = self
//cropper.cropRatio = 2/3 //(can be set with variable, before cropper is presented, or in cropper init)
//cropper.cropButtonText = "Crop" // button labes can be localised/changed
//cropper.cancelButtonText = "Cancel"

If just cropping existing UIImage there is no need to set up picker, delegate is enough. Just give image to croppen and present it.

cropper.picker = nil // Make sure not set the picker when doing existing image cropping
cropper.image = UIImage(named: "image")
viewController.present(cropper, animated: true, completion: nil)

For both cases implement UIImageCropperProtocol delegate method/s

func didCropImage(originalImage: UIImage?, croppedImage: UIImage?) {
    imageView.image = croppedImage
}

//optional (if not implemented cropper will close itself and picker)
func didCancel() {
    picker.dismiss(animated: true, completion: nil)
}

The UIImageCropper will handle the image picking (delegate methods). To start image picking just present the UIImagePickerController instance.

self.present(self.picker, animated: true, completion: nil)

For full usage exmaple see CropperExample in Example folder.

Issues and contribution

If you find any issues please add and issue to this repository.

Improvements and/or fixes as pull requests are more than welcome.

Author

Jari Kalinainen, jari(a)klubitii.com

License

UIImageCropper is available under the MIT license. See the LICENSE file for more info.

uiimagecropper's People

Contributors

jvk75 avatar jomnius avatar yalishanda42 avatar madsci356 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.