Coder Social home page Coder Social logo

gkimagepicker's Introduction

GKImagePicker

An enhancement of UIImagePicker in iOS to enable image cropping at any specified size as well as image rotation. So easy to use, even your computer illiterate grandma can (probably) figure it out.

Features

  • Grab a new image from your camera or an existing image from your gallery
  • Zoom and crop in any way you wish
  • Rotate image (tap the screen to show menu)
  • Takes into account UIImageOrientation so the images will show up the way they were intended
  • Rescale image after cropping, or keep image scale as-is

Setup

Copy all the files in GKImagePicker (including subfolders) into your project. Be sure to add them to your project target under "Build Phases" > "Compile Sources".

Use

The Short Version

GKImagePicker *picker = [[GKImagePicker alloc] init];
self.picker.delegate = self;
// (Optional) default: CGSizeMake(320., 320.)
self.picker.cropper.cropSize = CGSizeMake(160., 80.);   
// (Optional) default: YES
self.picker.cropper.rescaleImage = YES;
// (Optional) default: 1.0
self.picker.cropper.rescaleFactor = 2.0;
// (Optional) default: YES
self.picker.cropper.dismissAnimated = NO;
// (Optional) default: [UIColor colorWithRed:0/255. green:0/255. blue:0/255. alpha:0.7]
self.picker.cropper.overlayColor = [UIColor colorWithRed:0/255. green:0/255. blue:0/255. alpha:0.7];
// (Optional) default: [UIColor colorWithRed:0/255. green:0/255. blue:0/255. alpha:0.7]
self.picker.cropper.innerBorderColor = [UIColor colorWithRed:255./255. green:255./255. blue:255./255. alpha:0.7];
[self.picker presentPicker];

Or, if you already have the image you want to crop, you can skip the picker and go straight to the cropper:

GKImageCropper *cropper = [[GKImageCropper alloc] init];
cropper.delegate = self;
cropper.image = yourImage;
[self presentModalViewController:[[UINavigationController alloc] initWithRootViewController:cropper] animated:YES];

The Long Version

Import GKImagePicker:

#import "GKImagePicker.h"

Implement the GKImagePickerDelegate in your view controller:

@interface ViewController () <…, GKImagePickerDelegate> {

Initialize and set delegate:

GKImagePicker *picker = [[GKImagePicker alloc] init];
picker.delegate = self;

Modify the crop size:

picker.cropper.cropSize = CGSizeMake(88.,88.);

rescaleImage determines whether you want to rescale the image after it has been cropped. For example, given a 1000x1000 image and a 10x10 crop size, if rescaleImage == YES and rescaleFactor == 2.0, the image size in the end would be 20x20. However, if rescaleImage == NO, it would keep whatever was shown in the crop box without rescaling - if the image was zoomed out all the way, the resulting image would be 1000x1000.

picker.cropper.rescaleImage = YES;
picker.cropper.rescaleFactor = 2.0;

dismissAnimated determines whether the cropper will be dismissed at the very end with an animation.

picker.cropper.dismissAnimated = YES;

Show the GKImagePicker:

[picker presentPicker];

Add a delegate method to get back the final cropped/resized image:

- (void)imagePickerDidFinish:(GKImagePicker *)imagePicker withImage:(UIImage *)image {
    // Do whatever you want with the image. I won't judge.
}

gkimagepicker's People

Contributors

genkikondo avatar

Watchers

James Cloos avatar  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.