GithubHelp home page GithubHelp logo

ruslanskorb / rskimagecropper Goto Github PK

View Code? Open in Web Editor NEW
2.4K 66.0 469.0 132.3 MB

An image cropper / photo cropper for iOS like in the Contacts app with support for landscape orientation.

License: MIT License

Ruby 0.75% Objective-C 98.42% Makefile 0.48% Swift 0.34%
crop cropping trimming cropper editor image photo contacts-app edit

rskimagecropper's People

Contributors

dbergman avatar dependabot[bot] avatar discobanan avatar edelabar avatar jjochen avatar jkrzemie avatar mohpor avatar nootfly avatar ogoldfinger avatar pronebird avatar ruslanskorb avatar serchinastico avatar timaktimak avatar timshadel avatar

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  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

rskimagecropper's Issues

DataSource Protocol stop working

Hey Ruslan,
I'm trying to changing radius in the maskRect (want to make it small), but it's looks like dataSource Protocol stop working.

I use the following code:

RSKImageCropViewController *imageCropVC = [[RSKImageCropViewController alloc] initWithImage:image];
imageCropVC.delegate = self;
imageCropVC.dataSource = self;
[self presentViewController:imageCropVC animated:nil completion:nil];

delegate are working, but the dataSource are not.

Could you please have a look? And yes, I have not forgot to add :)

Btw, thank you for the great framework!

Regards,
Anton

Doesn't work with 2x and 3x images

Thanks for this cool library!

In example project, in Images.xcassets, add an image as 2x (or 3x) for photo, then build on a retina screen. Cropped image does not match cropped area at all.

It seems that scale is not handled correctly when generating cropRect (and the resulting croppedImage).

Note that any generated UIImage will have a scale of 2 on retina devices (ex: an image fetched online).

Different sizes when zooming?

Hi, I don't know if I understand the library correctly, but if you see this example app I did with your code http://cl.ly/ZLhB you will notice that the resulting croppedImage is changing when I scale the underlaying image.

Is this correct? shouldn't the returned croppedImage always be in the same size?

Not working for App Extensions

Because [UIApplication sharedApplication] is not accessible in app extensions.

The common way of solving this is adding a macro "APP_EXTENSION=1" for the app extension target and checking for it.

It seems you only use it for status bar purposes. You should know that status bar behaves really weird in app extensions (inherit parent app behavior, NOT customizable), so not trying to define/style it if in an app extension would work.

Crop without controller

Hi, thanks for this control :)

This is an enhancement request, I don't want to show cropper view controller, please provide a direct method which take an image as input and give cropped output with given size.

Custom Image Cropper

Hello, I am trying to implement a UIImagePicker with custom cropper. I have searched for a similar error and the answer was "the imageCropViewControllerCustomMaskPath wasn't implemented", but I have implemented mine, so I'm not sure what's the issue here. Any help would be appreciated. Thanks in advance.

//UIImagePickerControllerDelegate
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {

    picker.dismissViewControllerAnimated(true) { () -> Void in
        let imageCropVC = RSKImageCropViewController(image: image, cropMode: RSKImageCropMode.Custom)
        imageCropVC.delegate = self

        self.presentViewController(imageCropVC, animated: true, completion: nil)
    }
}

//RSKImageCropViewControllerDelegate, RSKImageCropViewControllerDataSource
func imageCropViewControllerDidCancelCrop(controller: RSKImageCropViewController) {
    dismissViewControllerAnimated(true, completion: nil)
}

func imageCropViewController(controller: RSKImageCropViewController, didCropImage croppedImage: UIImage, usingCropRect cropRect: CGRect) {
    //Do some stuff here with the image.

    dismissViewControllerAnimated(true, completion: nil)
}

func imageCropViewControllerCustomMaskRect(controller: RSKImageCropViewController) -> CGRect {
    //let maskSize = CGSizeMake(320, 320)
    let maskRect = CGRectMake(0 , 30, 260, 260)
    return maskRect
}

func imageCropViewControllerCustomMaskPath(controller: RSKImageCropViewController) -> UIBezierPath {
    let rect = controller.maskRect
    let point1 = CGPointMake(CGRectGetMinX(rect), CGRectGetMaxY(rect))
    let point2 = CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect))
    let point3 = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect))

    let triangle = UIBezierPath()
    triangle.moveToPoint(point1)
    triangle.moveToPoint(point2)
    triangle.moveToPoint(point3)
    triangle.closePath()

    return triangle;
}

func imageCropViewControllerCustomMovementRect(controller: RSKImageCropViewController) -> CGRect {
    let rect = controller.maskRect
    return rect;
}

Error is:

Jan  4 19:54:40  App[10148] <Error>: CGAffineTransformInvert: singular matrix.
Jan  4 19:54:40  App[10148] <Error>: CGAffineTransformInvert: singular matrix.
Jan  4 19:54:40  App[10148] <Error>: CGAffineTransformInvert: singular matrix.

Change color and circle diameter

Hi, thanks for the great component! This is 98% of what I need. The 2% is I need to be able to change the diameter of the crop circle and change the crop layer color to something other than black. Will you be able to do this or should I submit a pull request? Thanks again!!!

how to crop image in triangular shape

Hi,
I would like to congratulate you for making such an excellent control.
However can you provide solution from triangular crop as you have already added circular and square shape

Can't import RSKImageScrollView

With last 1.5.0 update my compilation fails when installing the library using Cocoapods, complaining it can't find the file.

I am using RSKimageScrollView (amongst others) in my code, but noticed in the last update only a few headers were exposed:

s.public_header_files = [ 'RSKImageCropper/RSKImageCropper.h', 'RSKImageCropper/RSKImageCropViewController.h', 'RSKImageCropper/RSKImageCropViewController+Protected.h' ]

I wonder if this was intended?
My assumption is it's a mistake as it breaks backwards compatibility for some use cases of the library.

Have a PR ready that fixes the issue in case I'm right. #93

RSKImageCropModeSquare does not return perfectly square UIImages for some images

Using RSKImageCropModeSquare does not always return a perfect square for every image I crop. For example cropping this image at minimum zoom produces an image of 418 x 417

11873728_1481365722181855_881550142590002518_n

And this image comes out at 405 x 404

11892068_1481361512182276_6954866757201721945_n

However cropping this image produces an image of 437 x 437

11885749_1481361705515590_437187395147819092_o

It is important for me that a perfect square is returned.

avoidEmptySpaceAroundImage is set in both cases.

Any help would be great.

Thanks

UIStatusBar color problem

Hi, i'm trying to use this amazing library, but i have a problem, when i dismiss the RSKImageCropperViewController the status bar become black, instead in my app i have a light color status bar. how i can fix it?

Problem with CustomMaskRect

Hi, first of all, thanks for this amazing library :)

I'm trying to use a custom size rect to crop and image, so I'm using this:

RSKImageCropViewController *imageCropVC = [[RSKImageCropViewController alloc] initWithImage:image cropMode:RSKImageCropModeCustom];
        imageCropVC.delegate = self;
        imageCropVC.dataSource = self;

Then, I implemented the delegate and data source methods like this

- (CGRect)imageCropViewControllerCustomMaskRect:(RSKImageCropViewController *)controller
{
    CGSize maskSize;

    CGFloat maskWidth = [UIScreen mainScreen].bounds.size.width;
    CGFloat maskHeight = ceilf(self.view.frame.size.height * 0.4f);

    NSLog(@"MASK WIDTH: %f", maskWidth);
    NSLog(@"MASK HEIGHT: %f", ceilf(maskHeight));
    maskSize = CGSizeMake(maskWidth, maskHeight);

    CGRect maskRect = CGRectMake((self.view.frame.size.width - maskSize.width) * 0.5f,
                                 (self.view.frame.size.height - maskSize.height) * 0.5f,
                                 maskSize.width,
                                 maskSize.height);

    return maskRect;
}

- (UIBezierPath *)imageCropViewControllerCustomMaskPath:(RSKImageCropViewController *)controller
{
    CGRect rect = controller.maskRect;

    CGPoint point1 = CGPointMake(CGRectGetMinX(rect), CGRectGetMinY(rect));
    CGPoint point2 = CGPointMake(CGRectGetMaxX(rect), CGRectGetMinY(rect));
    CGPoint point3 = CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect));
    CGPoint point4 = CGPointMake(CGRectGetMinX(rect), CGRectGetMaxY(rect));

    UIBezierPath *rectangle = [UIBezierPath bezierPath];

    [rectangle moveToPoint:point1];
    [rectangle addLineToPoint:point2];
    [rectangle addLineToPoint:point3];
    [rectangle addLineToPoint:point4];
    [rectangle closePath];

    return rectangle;
}


- (CGRect)imageCropViewControllerCustomMovementRect:(RSKImageCropViewController *)controller
{
    return controller.maskRect;
}

And, on my console (texting with an iPhone 6S) I'm getting this:

2016-02-09 17:36:28.705 HorseWare[716:140715] MASK WIDTH: 375.000000
2016-02-09 17:36:28.705 HorseWare[716:140715] MASK HEIGHT: 267.000000
2016-02-09 17:37:05.540 HorseWare[716:140715] CROPPED IMAGE SIZE: 1936.000000, 1125.000000
2016-02-09 17:37:05.540 HorseWare[716:140715] CROPPED RECT SIZE: 1936.000000, 1125.000000

So, I'm not getting the same size neither the same aspect ratio for the custom rect mask.

MASK WIDTH / MASK HEIGHT = 1.40
CROPPED RECT WIDTH / CROPPED RECT HEIGHT = 1.72

Why is that happening?

Thanks for your time

Workspace Empty

I have downloaded the source and trying to run But as I open workspace but didn't able to compile the code... Pods are missing.What I need to run this source code.

Define a minimum output size?

Instagram photos are 640 x 640 pixels in size. I would like to make this the minimum size that an image can be cropped to. Could you (or anyone) suggest how I might go about achieving this?

Connection to assetsd was interrupted or assetsd died

I have encountered this issue when I try to reload a panoramic image (10mb) in RSKImageCropViewController.

Steps:

  1. Load pano image using UIImagePickerController with source type UIImagePickerControllerSourceTypePhotoLibrary.
  2. Then "Choose" on RSKImageCropViewController (The UI lags here before going back to the previous view controller).
  3. Cropped image is now assigned to the imageView.
  4. Load again (back to step 1; with same image).

In step 4, I can see the image is displayed in the RSKImageCropViewController but now crashes. If I load images with lower file size, it can handle it.

I'm not sure where to handle this error or are there any workarounds on this?

Thank you.

(sorry, mistakenly pressed close issue)

can we provide a property to fixed size

I set the RSKImageCropMode = RSKImageCropModeSquare , when I zoom the image smaller ,the MaskRect is smaller with image, not to be a square . can we fixed the size and not changed with image zoom

RSKImageCrop for swift

Hi ,

I installed this library using pods. Currently I am working on Xcode 7.0.1
After pod installation , I imported
#import <RSKImageCropper/RSKImageCropper.h>
in MyProject-Bridging-Header.h

It is showing an error No such module

Rectangle cropping with custom crop mask and avoidEmptySpaceAroundImage = YES

ios simulator screen shot 3 lip 2015 20 42 30
Hey, could you tell me how to calculate correct avoidness for empty space around image using rectangle, which formalus did you use to do it for Square, because it works perfectly fine!! If i am trying to do it for rectangle sometimes it doesn't avoid empty space. Help will be appreciated. Thanks.I attached image to see how it looks like

Ninety degrees clockwise rotation

Hi
I added a functionality to rotate the image by ninety degrees clockwise, the functionality is disabled by default and can be enabled setting the parameter '''fixedRotationEnabled''' to YES, this shows a button that allows the rotation. Also added a few test for this.

I have a fork with the changes (https://github.com/estebansotoara/RSKImageCropper/tree/ninetyDegreesRotation), you can check it out and if you like it I can make a PR

BTW: there are 8 test that are failing, checked on a clean copy of master and are failing there too so idk if it is a known issue or just failing to me for some strange reason

Tests: Unit Test

Things I'd like if you're adding tests for this project:

Tooling: Specta/Expecta, XCTest

Areas to look at:

  • [RSKImageScrollView] Display image.
  • [UIImage+RSKImageCropper] Image orientation.
  • [UIImage+RSKImageCropper] Image rotation.
  • [CGGeometry+RSKImageCropper] Line segment intersection.
  • [RSKImageCropViewController] Can be created.
  • [RSKImageCropViewController] Crop mode - snapshots.
  • [RSKImageCropViewController] Delegate.
  • [RSKImageCropViewController] Data source.
  • [RSKImageCropViewController] Avoid empty space around image.
  • [RSKImageCropViewController] Rotation.
  • [RSKImageCropViewController] Handle double tap.
  • [RSKImageCropViewController] Reset zoom scale.
  • [RSKImageCropViewController] Reset content offset.
  • [RSKImageCropViewController] Reset frame.
  • [RSKImageCropViewController] Crop Performance.

Notes:

Do you submit your code for pod?

when i use pod 'RSKImageCropper', and run pod install, i found that the code missing the custom UI feature?

/**
The mode for cropping.
*/
@Property (assign, nonatomic) RSKImageCropMode cropMode;

/// -------------------------------------------
/// @name Checking of the Interface Orientation
/// -------------------------------------------

/**
Returns a Boolean value indicating whether the user interface is currently presented in a portrait orientation.

@return YES if the interface orientation is portrait, otherwise returns NO.
*/

  • (BOOL)isPortraitInterfaceOrientation;

@EnD

Custom crop size at runtime

Hello,

Thanks a lot for the great library. I'd love to have support for a custom cropSize at runtime. You could simply add a boolean resizable variable and if it's set to true, the edges of the maskLayer can be dragged (to increase or decrease the width and the height of the mask).

Let me know if you are going to add this feature :)

Thanks.
Patrick

NSLocalizedString table and bundle name

It would be nice to be able to provide table and bundle name, which RSKImageCropper would use in all NSLocalizedString calls. Currently with Pods localization is not possible.

Swift: Include of non-modular <tgmath.h>

Hi,

I'm trying to use your pod in my project that's developed using Swift, but after installing it I get the following error:

/Users/william_oanta/Agilio/iOS-App/Pods/RSKImageCropper/RSKImageCropper/CGGeometry+RSKImageCropper.h:26:9: Include of non-modular header inside framework module 'RSKImageCropper.CGGeometry_RSKImageCropper'

I have set in Build Settings 'Allow Non-modular Includes in Framework Modules to YES for both the Live Vicarious and the Pods workspace, and it is still not working.

Here you have some screenshoots:

screenshot 2015-10-21 13 58 34
screenshot 2015-10-21 13 58 54
screenshot 2015-10-21 13 59 28
screenshot 2015-10-21 14 00 12
screenshot 2015-10-21 14 00 34

I have tried your demo example and it's working on the same environment - but I saw that you don't use Swift, and I guess this is a Swift caused problem. Any clue on how to fix it?

Thanks

hey. i need a little help

If I have a picture taken in iphone landscape mode. The cropper view gets the image turned 90degree left. How can I make it not to turn the image at any condition ? By the way sorry if my English is bad.

Example Project

Hi there,

I don't seem to be able to compile the example project due to podfile errors. 'pod install' ran fine, but xCode tells me

diff: /../Podfile.lock: No such file or directory
diff: /Manifest.lock: No such file or directory
error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.

Do you know what this could mean?

Thanks and regards,
Sebastian Mecklenburg

I want to crop image square

I want to cut image in square , i changed this line _cropMode = RSKImageCropModeCircle to
RSKImageCropModeSquare but not working

Necessary variables are not accessible

I wanted to suggest that you make the following variables parameters, or at least make them available for change by including them in the .h file. I want to eliminate the space around my circle mask so that it fills the screen width-wise. Also, for iPhone 4S and showing the crop view controller in a popover in the iPad, the "move and scale" label is right on top of the crop area.

//static const CGFloat kPortraitCircleMaskRectInnerEdgeInset = 15.0f;
//static const CGFloat kPortraitSquareMaskRectInnerEdgeInset = 20.0f;
static const CGFloat kPortraitCircleMaskRectInnerEdgeInset = 0.0f;
static const CGFloat kPortraitSquareMaskRectInnerEdgeInset = 0.0f;
//static const CGFloat kPortraitMoveAndScaleLabelVerticalMargin = 64.0f;
static const CGFloat kPortraitMoveAndScaleLabelVerticalMargin = 30.0f;

//static const CGFloat kLandscapeCircleMaskRectInnerEdgeInset = 45.0f;
//static const CGFloat kLandscapeSquareMaskRectInnerEdgeInset = 45.0f;
static const CGFloat kLandscapeCircleMaskRectInnerEdgeInset = 0.0f;
static const CGFloat kLandscapeSquareMaskRectInnerEdgeInset = 0.0f;

imageCropViewControllerCustomMaskRect not working

Hi there,

I loved the library for circular and square crops, although I am having trouble with custom size crops.

I've initiated the RSKImageCropViewController with the custom size parameter and also implemented the RSKImageCropViewControllerDataSource in my own controller, but the method imageCropViewControllerCustomMaskRect is never called.

// Instantiation:
RSKImageCropViewController *cropViewController = [[RSKImageCropViewController alloc] initWithImage:self.selectedImageButton.originalImage
                                                                                          cropMode:RSKImageCropModeCustom];

// Delegate method:
- (CGRect)imageCropViewControllerCustomMaskRect:(RSKImageCropViewController *)controller {
    NSLog(@"Test");
    return CGRectMake(0, 0, 250, 250);
}

What I really want is to define a custom rect for the cropper every time it is called. If I could do it in the initiation method, that'd be great but it looks like the only way is to implement the delegate method, which is not working for me.

What may I be doing wrong?

Thanks

CGBitmapContextCreate: unsupported parameter combination and other errors

When I select the image by tapping "Choose" after editing, I get the following errors. Have no idea why this is happening.

Dec 1 15:32:35 MyApp : CGBitmapContextCreate: unsupported parameter combination: set CGBITMAP_CONTEXT_LOG_ERRORS environmental variable to see the details
Dec 1 15:32:35 MyApp : CGContextSetInterpolationQuality: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Dec 1 15:32:35 MyApp : CGContextTranslateCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Dec 1 15:32:35 MyApp : CGContextConcatCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Dec 1 15:32:35 MyApp : CGContextDrawImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Dec 1 15:32:35 MyApp : CGBitmapContextCreateImage: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

Return the original image in the delegate methods

The cropped image is returned in the delegate method, but the original image is not returned. This is an issue if, for example, we call RSKImageCropper from

  • (void)imagePickerController:(UIImagePickerController *)imagePicker didFinishPickingMediaWithInfo:(NSDictionary *)info

Unless we save the original image into a property at this point, we lose it. It would be a handy option to return the original image in the delegate method for RSKImageCropper.

Add MaskPath border line

Like this

1

For example, when the pictures are black, the situation will be like,

131 2x

although i can change maskLayerColor, but I think add to add a border is a good user experience

Circular shape cropping

I have review your source code , Mind blowing cropping work But It actually cropping in rectangular form not in circular form ,It seem like you are showing the rectangular(cropped image) into circular form .
Can you tell me how to crop a image in proper circular and oval shape.

Stroked outline problem

Thanks for providing such a great tool.

When set the maskLayerStrokeColor RSKImageCropViewController view outline also set the maskLayerStrokeColor in left and top, and stroked outline not the same thickness contour.
12

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.