Coder Social home page Coder Social logo

igrsoft / igrphototweaks Goto Github PK

View Code? Open in Web Editor NEW
236.0 10.0 72.0 3.05 MB

Drag, Rotate, Scale and Crop

Home Page: https://igrsoft.com

License: MIT License

Swift 86.46% Ruby 1.01% Objective-C 12.53%
swift image-processing crop-image crop cropping rotation drag photos scale image

igrphototweaks's Introduction

[The Project is not served, please, enjoy forward :)]

U can use Mantis

IGRPhotoTweaks

IGRPhotoTweaks

IGRPhotoTweaks is a swift 4.2 library allow to expand an interface to crop photos, based on PhotoTweaks. It can let user drag, rotate, scale the image, and crop it. You will find it mimics the interaction of Photos.app on iOS 9. :]

Build Status Pod Version Platform License


Contribute to Development Goals Here:

BTC: 16tGJzt4gJJBhBetpV6BuaWuNfxvkdkbt4

BCH: bitcoincash:qpcwefpxddjqzdpcrx6tek3uh6x9v7t8tugu30jvks

LTC: litecoin:MLZxuAdJCaW7LdM4sQuRazgdNvd8G2bdyt


Usage

IGRPhotoTweaksViewController is a base interface for YourPhotoTweaksViewController. IGRPhotoTweaksViewController offers all the operations to crop the photo, which includes translation, rotate and scale.

To use it,

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "showCrop" {

        let yourCropViewController = segue.destination as! YourPhotoTweaksViewController
        yourCropViewController.image = sender as! UIImage
        yourCropViewController.delegate = self;
    }
}

self.cropAction() is the func calls the edit done action.

self.dismissAction() is the func calls the cancel edit action.

self.changedAngel(value: radians) is the func to set rotation angle.

self.setCropAspectRect(aspect: "9:16") is the func to set aspect ratio for crop view.

self.resetAspectRect() is the func resets all previous aspect ratio.

self.resetView() is the func resets all previous actions.

Get the cropped image

extension ViewController: IGRPhotoTweakViewControllerDelegate {
    func photoTweaksController(_ controller: IGRPhotoTweakViewController, didFinishWithCroppedImage croppedImage: UIImage) {
        self.imageView?.image = croppedImage
        _ = controller.navigationController?.popViewController(animated: true)
    }

    func photoTweaksControllerDidCancel(_ controller: IGRPhotoTweakViewController) {
        _ = controller.navigationController?.popViewController(animated: true)
    }
}

Setup IGRPhotoTweaks Controller

override func viewDidLoad() {
    super.viewDidLoad()

    self.isAutoSaveToLibray = true
}

Setup/Control Angle

fileprivate func setupSlider() {
    self.angleSlider?.minimumValue = -Float(IGRRadianAngle.toRadians(45))
    self.angleSlider?.maximumValue = Float(IGRRadianAngle.toRadians(45))
    self.angleSlider?.value = 0.0
}

@IBAction func onChandeAngleSliderValue(_ sender: UISlider) {
    let radians: CGFloat = CGFloat(sender.value)
    self.changeAngle(radians: radians)
}
    

Customize View

override open func setupThemes() {
    IGRCropLine.appearance().backgroundColor = UIColor.green
    IGRCropGridLine.appearance().backgroundColor = UIColor.yellow
    IGRCropCornerView.appearance().backgroundColor = UIColor.purple
    IGRCropCornerLine.appearance().backgroundColor = UIColor.orange
    IGRCropMaskView.appearance().backgroundColor = UIColor.blue
    IGRPhotoContentView.appearance().backgroundColor = UIColor.gray
    IGRPhotoTweakView.appearance().backgroundColor = UIColor.brown
}

override open func customBorderColor() -> UIColor {
    return UIColor.red
}

override open func customBorderWidth() -> CGFloat {
    return 2.0
}

override open func customCornerBorderWidth() -> CGFloat {
    return 4.0
}

override open func customCropLinesCount() -> Int {
    return 3
}

override open func customGridLinesCount() -> Int {
    return 4
}

override open func customCornerBorderLength() -> CGFloat {
    return 30.0
}

override open func customIsHighlightMask() -> Bool {
    return true
}

override open func customHighlightMaskAlphaValue() -> CGFloat {
    return 0.3
}

Example

IGRPhotoTweaks.xcodeproj -> IGRPhotoTweaks target /Example


Installation

IGRPhotoTweaks is available on CocoaPods. Add the follwing to your Podfile:

pod 'IGRPhotoTweaks', '~> 1.0.0'

Alternatively, you can manually drag the IGRPhotoTweaks folder into your Xcode project.


Issues

Not works in Objective-C


Protip

If using with an existing UIImagePickerController, be sure to set allowsEditing = NO otherwise you may force the user to crop with the native editing tool before showing IGRPhotoTweaksViewController.

igrphototweaks's People

Contributors

climbatize avatar ikorich avatar levidahl avatar mantergo avatar mihirmehtadet avatar ykying 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

igrphototweaks's Issues

Dynamic change of image.

@ikorich
Need possibility, to change the image dynamically. Cause I use your library in my VIPER project with custom navigation I need to set an image placeholder at first, and on completion set real image that I want to crop.

Questions:

  • Can your library handle it?
  • Maybe am I doing something wrong?
  • If not your suggestions on how to do it without changing of library concept?

P.S. I'll make PR with your suggestions to fix this.

Thank you in advance.

Not working for Mirrored orientation

If we select any image with any of mirrored orientation (upMirrored,leftMirrored,rightMirrored,bottomMirroed)
then it Does't gived correct output image.

Aspect ratio

Hi,

I have seen that but i want to know that when user select the image for
first time it is setting cropview as of imagesize. It is calculating
maxbounds (). I want to know how will it set 1:1 aspect ratio and lock it
by default.

Thanks
Ritika

Add Valid Frame

Added Valid frame for Crop View, when user change size of it

Should zoom to screen after scale changes

Whenever user dragged to crop
it should zoop to fill screen same in photos app
or user change aspect ratio value from action sheet should also zoom to screen
how to implement this functionality.

Fixed Aspect Ratio not working in Pods

I can make it work in your Example, but when I use Pods to install in my project the functions are not available. Seems like it's not pushed to master Pod release?

After setting the aspect ratio, user should not be able to change it.

If I am setting the aspect ratio to 16:9 , because i want to force user to maintain that aspect ration while selecting the image.

User is able to change the aspect ratio to something else other than 9:16

There should be Boolean variable for example shouldLockAspectRatio , If that variable is set to be true , User should not be able to change the aspect ratio.

Swift 5 support

All the features are good.
Is there any way to get Swift5 support ?

Errors

Hi @ikorich

I resolved that issue for horizontal Dial.
I am facing few more issues like

Unknown class _TtC7Example25ExampleCropViewController in Interface Builder file.
2017-05-25 15:52:10.062683+0530 Example[266:8830] *** NSForwarding: warning: object 0x100096720 of class 'Example.ExampleCropViewController' does not implement methodSignatureForSelector: -- did you forget to declare the superclass of 'Example.ExampleCropViewController'?
2017-05-25 15:52:10.063087+0530 Example[266:8830] *** NSForwarding: warning: object 0x100096720 of class 'Example.ExampleCropViewController' does not implement doesNotRecognizeSelector: -- abort

One issue I resolved by making pickerview.allowsediting = true
but still I am not able to run example in my device.

Please let me know whats wrong ?

Thanks !!

Need to use some internal variables of the pod in other ViewControllers

Hi!

I am currently building an app to measure the pixels in a cropped image. This is why I need to use some internal variables of the pod such as:

  • internal lazy var photoView in the IGRPhotoTweakViewController.swift. Changed it to public lazy var photoView
  • private(set) lazy var photoContentView in the IGRPhotoTweakView.swift. Changed it to public private(set) lazy var photoContentView

Do you think you can change this variables to public so I can still use the pod in the future to crop the image and still be able to obtain the pixels without having to modify the internal code you have created?
Also, I would like to thank you for this amazing program, it has helped me a lot! I will attach the files in which I did the changes from private to public in case you want to take a look.
podChanges.zip

Best regards,

Manuela

Crop area does not scale when image is rotated 90 degrees.

When rotating the image clockwise / counter-clockwise by 90 degrees, it seems like the crop area cannot select the whole image (even using original aspect does not work) and is still bound to the initial image size. Is there a way to update the crop area bounds when the image is rotated? Thanks!

You can reproduce the issue by manually setting the angle value.

self.changedAngle(value: 90.0)

Changeable Crop lines

Kindly help me with the case in which I want to change the number of crop lines with the change of aspect ratio

Unable to run

I am trying to run this code and i have installed pods but i got error like in following image, Please Help.
screen shot 2017-10-05 at 11 21 58 am

Crash while Cropping image

When we transform image & click on crop, it is crashing as context in CGImage+IGRPhonoTweakExtension.swift is nil.

Disable changing of crop area size

Hi!

I need to lock the crop area, so the user are not able to change the size. I want to set some fixed aspect ratios e.g. 16:9 and user should not be able to move the white lines. So the solution is "not" to set just:
self.lockAspectRatio(true). This will still allow users to move the white lines... I need to disable it completly. Is it possible?

pods file missing

Hi

Pods file are missing in the project

screen shot 2017-05-23 at 7 03 45 pm

I created new pod file and new work space for example. After this pods issue got resolved, but after this horizontalDial was not available.

Anyone can help me out its little urgent !!

Thanks

lock aspect ratio and aspect ratio by default

hi,

I wanted to set the aspect ratio as 1:1 by default and it should be locked. How to achieve this. When first time image is selected the crop area is same as image view area I need that aspect ratio to be 1:1. Please help

Thanks

Ritika

New release?

The latest release of 1.0.6 is several checkins behind.

Can you create another release from master?

how to rotate 90°

when i set slider to -90~90 the crop area do not match the image.
wish your help.

Latest update does not reflact via Pods for swift 4.2 support

I have added IGRPhotoTweaks to my project using cocoapods which downloading version '1.0.7'. But it does not contains updated code with Swift 4.2 support. I have attached screenshots here:

Screenshot 1:
screen shot 2019-01-02 at 2 57 01 pm

Screenshot 2:
screen shot 2019-01-02 at 3 01 15 pm

Screenshot 3:
screen shot 2019-01-02 at 3 00 25 pm

Screenshot 4:
screen shot 2019-01-02 at 3 00 46 pm

Screenshot 5:
screen shot 2019-01-02 at 3 01 08 pm

Bug when rotating

Hello!
I using this func:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: nil, completion: (
{(context) in
self.view.layoutIfNeeded()
self.resetView()
self.resetAspectRect()
}
))
}
But sometimes(more often) AspectRect does not display correctly
How i can fix it?
Thanks!

App crash

App crash on click on crop button if i select image from screenshot folder its working fine if I select image via camera. Crash only in iOS 13 and above.

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.