Coder Social home page Coder Social logo

tribemedia / ios-image-editor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from heitorfr/ios-image-editor

0.0 4.0 0.0 302 KB

iOS View Controller for image cropping. An alternative to the UIImagePickerController editor with extended features.

ios-image-editor's Introduction

iOS Image Editor

A iOS View Controller for image cropping. An alternative to the UIImagePickerController editor with extended features and flexibility. Drop me a line if your're using this on your apps, I would like to know.

Features

  • Full image resolution
  • Unlimited pan, zoom and rotation
  • Zoom and rotation centered on touch area
  • Double tap to reset
  • Handles EXIF orientations
  • Plug-in your own interface

Usage


HFImageEditorViewController *imageEditor = [[HFImageEditorViewController alloc] initWithNibName:@"DemoImageEditor" bundle:nil];

imageEditor.sourceImage = image;
imageEditor.doneCallback = ^(UIImage *editedImage, BOOL canceled){
    ...
}

Configuration Properties

sourceImage

The full resolution UIImage to crop

previewImage

For images larger than 1024 wide or 1024 height, the image editor will create a preview image before the view is shown. If a preview is already available you can get a faster transition by setting the preview propety. For instance, if the image was fetched using the UIImagePickerController:


UIImage *image =  [info objectForKey:UIImagePickerControllerOriginalImage];
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];

[self.library assetForURL:assetURL resultBlock:^(ALAsset *asset) {
    UIImage *preview = [UIImage imageWithCGImage:[asset aspectRatioThumbnail]];
HFImageEditorViewController *imageEditor = [[HFImageEditorViewController alloc] 
	initWithNibName:@"DemoImageEditor" bundle:nil];
    self.imageEditor.sourceImage = image;
    self.imageEditor.previewImage = preview;        
...
} failureBlock:^(NSError *error) {
    NSLog(@"Failed to get asset from library");
}];

doneCallback

The callback block called when the image editor completes. Returns the cropped image and a BOOL that specifies if completion results from a done or cancel actions.

cropSize

A CGSize specifying the width and height of the crop area in screen coordinates. NOTE: Currently HFImageEditorViewController is expecting cropSize to be set only after its view and the frameView outlet have been set. If you subclass HFImageEditorViewController you can do it in viewDidLoad; if not, you should set it after adding HFImageEditorViewController to the view controller hierarchy.

cropRect

A CGRect specifying the crop area in screen coordinates. Use instead of cropSize if the crop area is not centered. NOTE: Currently HFImageEditorViewController is expecting cropRect to be set only after its view and the frameView outlet have been set. If you subclass HFImageEditorViewController you can do it in viewDidLoad; if not, you should set it after adding HFImageEditorViewController to the view controller hierarchy.

outputWidth

The width of the cropped image. If not defined, the width of the source image is assumed.

minimumScale, maximumScale

The bounds for image scaling. If not defined, image zoom is unlimited.

checkBounds

Set to true to bound the image transform so that you dont' get a black backround on the resulting image.

panEnabled, rotateEnabled, scaleEnabled, tapToResetEnabled

BOOL property to enable/disable specific gestures

Output Properties

####cropBoundsInSourceImage Returns a CGRect representing the current crop rectangle in the source image coordinates. Source image coordinates have the origin at the bottom left of the image. Note that, if rotation has been applyed, then cropBoundsInSourceImage represents the bounding box of the rotated crop rectangle.

Interface

Create your own xib for a custom user interface.

  • Set HFImageEditorViewController (or subclass) as the file owner
  • Set the frameView outlet. This view must implement the HFImageEditorFrame protocol. It must be transparent in the crop area, the image will show behind. A default implementation ImageEditorFrameView is provided
  • Connect interface elements to the available actions: done, reset, resetAnimated and cancel.

The demo app also shows how extended controlls can be implemented: three buttons are used for square, portrait and landscape crop.

Use the subclassing hooks (startTransformHook, endTransformHook) if you need to update the interface during image processing (to diable UI controls, for instance).

ChangeLog

1.1

Features:
  • New checkBounds setting to bound the image scale and pan to avoid clear space.

1.1.1

Features:
  • Crop rectangle does not have to be centered - use cropRect to specify the crop area instead of cropSize
  • One step transform - orientation fix and cropping on the same operation for improved memory footprint and speed
Bug fixes:
  • Support all EXIF orientation

1.1.2

Bug fixes:

Bound check now works correctly with any transform including rotation.

1.1.3

ios-image-editor is now using ARC

1.1.4

Bug fixes:

rotationEnabled, panEnabled, scaleEnabled, tapToResetEnabled where being ignored if set before the editor view was loaded.

License

MIT License

Copyright (c) 2012 Heitor Ferreira

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ios-image-editor's People

Contributors

heitorfr avatar iellis avatar kvting avatar orarbel avatar

Watchers

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