Git Product home page Git Product logo

gkimagepicker's Introduction

GKImagePicker

Ever wanted a custom crop area for the UIImagePickerController? Now you can have it with GKImagePicker. Just set your custom crop area and that's it. Just 4 lines of code. If you don't set it, it uses the same crop area as the default UIImagePickerController.

How to use it

  • just drag and drop the files in under "GKClasses" & "GKImages" into your project.
  • look at the sample code below.
  • this project contains a sample project as well, just have a look at the implementation of ViewController.m
  • have fun and follow @gekitz.

Sample Code

self.imagePicker = [[GKImagePicker alloc] init];
self.imagePicker.cropSize = CGSizeMake(320, 90);
self.imagePicker.delegate = self;

 [self presentModalViewController:self.imagePicker.imagePickerController animated:YES];

This code results into the following controller + crop area:

Sample Crop Image

It's even possible to let the user adjust the crop area (thanks to @pathonhauser for this pull request) by setting one additional property:

self.imagePicker.resizeableCropArea = YES;

This code results into the following controller + adjustable crop area: Sample Crop Image Adjustable

License

Under MIT. See license file for details.

gkimagepicker's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gkimagepicker's Issues

Corp image problem.

First of all this is the great code you have written.

I have one issue with cropping image with portrait mode landscape will work fine.

I have change the code to fetch image from library to camera, when I capture image as a landscape mode with camera it will work perfectly, but when I was capture image as portrait image, image shows in corp box as aspect to fit, my image crop box size is 300x 200 means landscape box, in landscape box portrait image not feet well.

1
2

First image is the current scenario. second image is what I am trying to say.

Because the reason behind If i am crop like a first image it still give (Output result after crop ) me the portrait image not landscape image...

When using Camera Status Bar Disappears

When I set up the app to use the camera instead of selecting from photo library, the status bar disappears when the camera view shows, and never reappears.

How to set maximum zoom ?

Is there any way to set maximum zoom of the taken picture ?. I don't understand when I tried to set image to UIButton and the picture is really small because I zoomed in to maximum, it's not really fill the size of button, there is a blank space in everyside of button.

iOS8: Camera Freeze on Cancel

Hi,

There is an issue on iOS8 that will stall the camera when the user cancels out of the crop-area.

Repro Steps:

  • Launch the GKImagePicker with a camera source and any crop size (resizable or not).
  • Take the photo.
  • Press 'Use Photo'.
  • In the crop image view, press 'Cancel'.
  • The crop image view should be dismissed, and goes back to the camera view.
  • On iOS8: The actual camera view is blurred out and doesn't reflect what the camera is seeing. You just see a static, blurred image. You can still however take an image, and the image is proper.
  • On iOS7: The actual camera view returns, enabling you to take another photo properly.

I suspect it may have to do with the way iOS8 handles action sheets (?), and the behaviour of dismissing the CropImageViewController. I'm currently investigating it.

Anyone bumped into this, or fixed it?

Fixing deprecated methods/calls

There are some deprecated methods/enums that can be fixed easily.

GKClasses/GKImageCropOverlayView.m

line 70: Change UILineBreakModeTailTruncation to NSLineBreakByTruncatingTail
line 71: Change UITextAlignmentCenter to NSTextAlignmentCenter

GKClasses/GKImageCropViewController.m

line 184: Remove viewDidUnload method, never gets called with ARC

ImagePicker

HI,
Great program. Thanks
on the resizable custom crop function the initial placement of the cropview and all the handles is correct. The handles along the vertical are only half circles as the image covers most of the popover view.
When a (any) handle is moved the cropview reduces in size, and all handles become full circles. The cropview seems to back away from the popover view boarder, and now covers part of the image. It is now impossible to get back to the initial position of the handles. There seems to be a constrain along the boarder of the popover view preventing the handles back to the initial condition.Is this correct and is this constrain adjustable.?

You can easily reproduce this on the demo program with the attached image.

Rashid
[email protected]
81vlf img

Scalable cropSize

Wouldn't it be great if the user could scale/change the cropRectangle?

Initialization of GKImagePicker hangs main thread.

This happens in the sample app the same as it does in my app.

Simply alloc-init'ing and presenting the view controller takes about 1 second, with the main thread blocked in the mean time. It's pretty clunky.

It wouldn't be too difficult to just send it off on a dispatch_async() and call back to the main thread when ready- but I think this should be covered GKImagePicker's implementation.

I'll test it in instruments and post info if I have time tomorrow.

Image from camera is not immediately able to be moved.

Seems like when you take an image with the camera, you cannot move it (pan it) immediately. If you zoom in a bit, the image is then able to be panned. I think this is tied to an issue with the content size, I corrected by using the faktored width and height.

In addition there was an issue where the image was positioned not exactly in the correct spot, fixed by setting the contentOffset.

in GKImageCropView.m

  • (void)layoutSubviews{
    //some code here...

    self.cropOverlayView.frame = self.bounds;
    //JJE - explicitly specify the content offset here to ensure there isn't a gap.
    self.scrollView.contentOffset = CGPointMake(0,0);
    self.scrollView.frame = CGRectMake(xOffset, yOffset, size.width, size.height);
    //JJE - changed the contentsize to the new width and height so we can move it immediately
    self.scrollView.contentSize = CGSizeMake(faktoredWidth, faktoredHeight);
    self.imageView.frame = CGRectMake(0, floor((size.height - faktoredHeight) * 0.5), faktoredWidth, faktoredHeight);
    }

I've got some other custom mods to this I can share.

Should use aspect ratio for the conditional statement when calculating the "faktor"

CGFloat imageAspectRatio = width / height;
CGFloat cropAspectRatio = size.width / size.height;
//    if(width > height){
if (imageAspectRatio > cropAspectRatio) {

    faktor = width / size.width;
    faktoredWidth = size.width;
    faktoredHeight =  height / faktor;

} else {

    faktor = height / size.height;
    faktoredWidth = width / faktor;
    faktoredHeight =  size.height;
}

Default zoomed In

Currently the default setting is Aspect-Fit to display the photo in the Crop viewer. I want this to be zoomed in, so that would be Aspect-Fill. However changing the setting for this is not working:

GKImageCropView.m

Change

self.imageView.contentMode = UIViewContentModeScaleAspectFit;

to AspectFill in the initWithFrame method:

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

        self.userInteractionEnabled = YES;
        self.backgroundColor = [UIColor blackColor];
        self.scrollView = [[ScrollView alloc] initWithFrame:self.bounds ];
        self.scrollView.showsHorizontalScrollIndicator = NO;
        self.scrollView.showsVerticalScrollIndicator = NO;
        self.scrollView.delegate = self;
        self.scrollView.clipsToBounds = NO;
        self.scrollView.decelerationRate = 0.0; 
        self.scrollView.backgroundColor = [UIColor clearColor];
        [self addSubview:self.scrollView];

        self.imageView = [[UIImageView alloc] initWithFrame:self.scrollView.frame];
        self.imageView.contentMode = UIViewContentModeScaleAspectFill;
        self.imageView.backgroundColor = [UIColor blackColor];
        [self.scrollView addSubview:self.imageView];


        self.scrollView.minimumZoomScale = CGRectGetWidth(self.scrollView.frame) / CGRectGetWidth(self.imageView.frame);
        self.scrollView.maximumZoomScale = 20.0;
        [self.scrollView setZoomScale:1.0];
    }
    return self;
}

Can anyone point me in the right direction?

low image quality

thanks for the library. However, the quality of the cropped image is very low (custom & resizable crop). If it helps, i'm using the cropped image for OCR using Tesseract. Upon The cropped image TOCR gives some vague symbols and just 1or 2 digits. If the apple's default picker is used, the OCR works perfectly.
Can you provide any help? Thanks.

Edit1: Forgot to mention, I modified the GKImagePicker.m to capture a new photo instead of choosing from library.
ps:
I'm using the latest version of library. I already read the issues #7, #11, #12, #32.

how can i localize strings

i want to localize the strings like 'choose photo', 'move and scale','use' , and i use the method of - (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName but i don't know the tableName, please help!

High Memory usage when cropping Panorama [IOS 7.1.1 multiple devices]

I'm just running the example application included in the project. When selecting a panorama in the Apple's Default Cropper, Memory usage is 15.5 MB. When using the Custom Cropper, it jumps to 88.6. This is using a 7.4 MB JPG, 8208 x 2332 image. I've done a lot of testing with other panoramas as well, it gets worse the larger the image is.

Within the context of another app, this is causing memory warnings, and in some cases, crashing the app.

Baseline:
screenshot 2014-08-15 16 42 44
Default:
screenshot 2014-08-15 16 42 55
Custom Crop:
screenshot 2014-08-15 16 43 10

VM Allocations is pointing to ImageIO as the culprit, but I haven't found a potential solution.

request visibleRect be returned

ie.

  • (void)imagePicker:(GKImagePicker *)imagePicker pickedImage:(UIImage *)image visibleRect:(CGRect *)visibleRect;

This is useful when integrating the image picker with an existing environment that crops server side.

Wrong item placement in iOS4.3 (iPad)

Hey there,

first of all, very nice work!! Your custom cropview for UIImagePicker was excactly what i was searching for!
I tested it in iOS5+ and everything works just fine!
But when i run your GKImagePicker on iOS4.3 in iPad simulator, all items are placed in the lower right corner of the popover. I figured out, that you use "self.view.bounds" for any size depending calculations. But this seem not be set properly in iOS4.3 when setting the "contentSizeForViewInPopover" property. By setting the view bounds properly everything is shown perfect, but i'm impossible to scale and move the image.
Can you confirm this issue? It would be nice if you could fix that.

kind regards

First zoom than move problem (with fix)

When loading the zoom and scale view you will have to zoom first before you can move the image.

This can be fixed if we set the contentsize of the scrollview larger than de cropsize.

GKImageCropView.m

  • (void)layoutSubviews

change:
self.scrollView.contentSize = CGSizeMake(size.width, size.height);
in:
self.scrollView.contentSize = CGSizeMake(width, height);

Example: Scaling on wrong axis

Hi, i noticed in some cases scaling is wrong. Example(resizeableCropArea=NO):
Image size: 200x100
Crop size: 120x110

I also noticed that it works OK when resizableCropArea=YES due to different scaling calculation. Using this seems to solve all problems for me, including square images, tested on 20+ images:

-(CGRect)_calcVisibleRectForCropArea
{
    CGFloat scale = self.imageView.image.size.width / self.imageView.frame.size.width;
    scale *= self.scrollView.zoomScale;

    //extract visible rect from scrollview and scale it
    CGRect visibleRect = [scrollView convertRect:scrollView.bounds toView:imageView];
    visibleRect = GKScaleRect(visibleRect, scale);

    return visibleRect;
}

Note: I always set images to normal orientation before passing them to GKImageCropViewController, otherwise it doesn't work.
BTW: Navigation bar sometimes disappears :P

Quality and size of image after cropping

Hi,

First, I would like to say that you did an awesome job with this component.

Running the test project, I am selecting an image from my camera roll that is:
1,856,278 bytes (1.9 MB on disk)

Running through all 3 options (Custom Crop, Normal Crop, and Resizable Custom Crop) and not cropping the image in anyway, I am capturing the size of the image when I select the Use button.
Custom Crop -> 12,210,978 bytes
Normal Crop -> 330,878 bytes
Resizable Custom Crop -> 287,723 bytes

I have the latest code and I am wondering if you could help me out here. I am working on a project where the user can crop an image and then I upload that image. When I upload, the size of the image is drastically reduced. Any help would be appreciated.

Thanks and keep up the good work.

Really low resolution after cropped with Resizable Custom crop

Just found a major bug
I just cropped a big image of a text document and the text is unreadable. If I go to my camera roll and zoom in on the text it's crisp and clear.
I've found out that a 2000x2000 image is now 600x500. (and the size of it haven't changed, I only cropped one line of pixels)
You can repredouce the bug by setting the crop points in Resizable Custom crop on a ZOOMED-OUT picture (this is where the bug is) If you'll zoom-in on the picture and then crop it it will be fine.
Thanks

app runs in emulator mode (scale 2x)

If my iPhone app runs in the emulator mode iPad i got an error

  • (void)layoutSubviews{

'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 240]'

width/faktoredWidth was devided by zero

Is there a possibility to use iphone only image picking on a ipad running the iphone app emulator?

I think i have to test this idom.

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone &&
[[[UIDevice currentDevice] model] hasPrefix:@"iPad"]) {
// This app is an iPhone app running on an iPad
}

If i remove all ipad idoms i still got this error.

When image orientation is not UIImageOrientationUp, the scaling doesn't work correctly

Steps to reproduce:

  • download the latest code
  • launch the demo
  • select an image whose orientation is UIImageOrientationUp, zoom-in heavily, crop; everything will work fine
  • now select an image whose orientation != UIImageOrientationUp, zoom-in heavily, crop; the crop is misplaced.

The screens below display both flows: first a correct crop, then the misplaced one.

photo 3
photo 4
photo 1
photo 2

Not getting the exact cropping.

hi,

I am using the GKImagePicker in my app.i have to display a image with width and height 320 * 320 . I keep the crop size as 320 *320. for some while little zooming of image i am getting the exact image while deep zooming , the image in the crop section is not displaying totally. only top of the image is displaying. please give suggestions for getting exact crop section of the image .in iPhone6 and 6 + exact cropping is occurring.

Please give suggestions

Thank you

Wrong crop size when presenting GKImagePicker in Popover in iPad landscape

Hi, I'm trying to use this amazing custom crop picker in my landscape only iPad app. I think the problem is my custom crop size is CGSizeMake(370, 550) which is bigger than the UIImagePicker default size in iPad landscape. And i tried for 2 days now but there doesn't seem a way to make the picker bigger.

Incorrect crop rect when move and scale squared images

GKImagePicker returns incorrectly cropped image for squared images (height == width). And I have found a solution, you need to replace in GKImageCropView.m this code:

" if (self.cropSize.width > self.cropSize.height) {
scale = (self.imageToCrop.size.width < self.imageToCrop.size.height ?
MAX(scaleWidth, scaleHeight) :
MIN(scaleWidth, scaleHeight));
}else{
scale = (self.imageToCrop.size.width < self.imageToCrop.size.height ?
MIN(scaleWidth, scaleHeight) :
MAX(scaleWidth, scaleHeight));
}"

with this one ("<" replaced with "<="):

" if (self.cropSize.width > self.cropSize.height) {
scale = (self.imageToCrop.size.width <= self.imageToCrop.size.height ?
MAX(scaleWidth, scaleHeight) :
MIN(scaleWidth, scaleHeight));
}else{
scale = (self.imageToCrop.size.width <= self.imageToCrop.size.height ?
MIN(scaleWidth, scaleHeight) :
MAX(scaleWidth, scaleHeight));
}"

sorry for my english :)

Drawing (cropsize) doesn't work on rectangles (not square)

Hello! this problem happens when the crop size is not a square, like for example 320x80.

  • you just pick a photo (no zoom, no moves), then click crop and the result is the original picture.
  • Even if you move the photo still not working, I mean it creates a result image but it's not what you selected.

Any suggestions?

Thanks!

errors when building new project

Hi,
I have created a new single view app. I dragged your files into the project and built it.
I get 12 error (see images below).
When running the demo app, there are no issues.
I have removed only GKImagePicker.m/h from my project and there are NO issues.
Any idea why this is?

EDIT:
needed to import UIKit

screen shot 2016-04-05 at 10 17 40 am
screen shot 2016-04-05 at 10 17 09 am

Memory leak after selecting a picture

I just noticed that right after I select an image from my camera roll and the crop viewController is opened I get a big memory leak. Is this a known issue or am I doing something wrong?

Screen Shot 2013-01-20 at 11 05 35 AM

Edit: After some digging I believe this is the problematic code under GKImageCropViewController:

  • (UIImage *)_toolbarBackgroundImage{
    ..
    ..
    CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, components, NULL, 2);

    CGContextDrawLinearGradient(ctx, gradient, CGPointMake(0, 0), CGPointMake(0, 54), kCGImageAlphaNoneSkipFirst);
    ..
    }

After commenting out those lines I lost my toolbar background Image (of course) but I also lost my leaks. And advice would be great.

Cropped squares sometimes have either width or height that is a pixel too small

This problem is caused because the scale is not always a whole number in the croppedImage function.

When the rect is scaled up, non full pixels are often created. When the CGImageCreateWithImageInRect cropping function crops the image, it rounds those non full pixels up!

This can be solved by changing this

static CGRect GKScaleRect(CGRect rect, CGFloat scale)
{
    return CGRectMake(rect.origin.x * scale, rect.origin.y * scale, rect.size.width * scale, rect.size.height * scale);
}

to this

static CGRect GKScaleRect(CGRect rect, CGFloat scale)
{
    return CGRectMake(floor(rect.origin.x * scale), floor(rect.origin.y * scale), floor(rect.size.width * scale), floor(rect.size.height * scale));
}

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.