ZImageCropper is a simplest way to crop image to any shapes you like.

Overview

ZImageCropper

CI Status Version License Platform

ZImageCropper is a simplest way to crop image to any shapes you like.

alt ZImageCropper

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

Cocoapods

ZImageCropper is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ZImageCropper'

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into Xcode and the Swift compiler.

If you are using Xcode 11 or later:

  1. Click File
  2. Swift Packages
  3. Add Package Dependency...
  4. Specify the git URL for ZImageCropper.
https://github.com/ZaidPathan/ZImageCropper

Manual

Add ZImageCropper.swift and ZImageCropperView.swift files to your project.

Usage

Crop using AI (Or programmatically)

Crop image using following code,

let croppedImage = ZImageCropper.cropImage(ofImageView: yourImageView, withinPoints: [
CGPoint(x: 0, y: 0),   //Start point
CGPoint(x: 100, y: 0),
CGPoint(x: 100, y: 100),
CGPoint(x: 0, y: 100)  //End point
])

Note : Make sure you provide valid points, points must be >=2 in count.

Crop using user touches,

Step 1: Add UIImageView to your StoryBoard/XIB and give it a Class Name: ZImageCropperView

Step 2: Run the app and see cropping is enable to your UIImageView

Step 3: Add @IBOutlet of your UIImageView and call method imageView.cropImage() to crop selected layer by user.

Author

Zaid Pathan

Contributor

Zaid Pathan, Devansh Vyas

License

ZImageCropper is available under the MIT license. See the LICENSE file for more info.

You might also like...
Morphi provides some additional shapes for SwiftUI.
Morphi provides some additional shapes for SwiftUI.

Morphi - ΞœΞΏΟΟ† Morphi provides some additional shapes for SwiftUI. Triangle Parallelogram(topLeftAngle) Polygon(sides) RoundedPolygon(sides, cornerRadi

Collection of SwiftUI shapes
Collection of SwiftUI shapes

SwiftUI Shapes Collection of custom shapes Regular Polygons RegularPolygon(sides: 32) RoundedRegularPolygon(sides: 6, radius: 20) Lines and Curves Qua

An instagram-like image editor that can apply preset filters passed to it and customized editings to a binded image.
An instagram-like image editor that can apply preset filters passed to it and customized editings to a binded image.

CZImageEditor CZImageEditor is an instagram-like image editor with clean and intuitive UI. It is pure swift and can apply preset filters and customize

RadarKit - The Radar Kit allowing you to locate places, trip neary by you Or it will help you to search out the people around you with the few lines of code
Create an '.icns' file from any image

createicns Create an '.icns' file from any image. Usage This command line tool makes it incredibly simple to create an '.icns' icon file from an image

πŸ“· A composable image editor using Core Image and Metal.
πŸ“· A composable image editor using Core Image and Metal.

Brightroom - Composable image editor - building your own UI Classic Image Editor PhotosCrop Face detection Masking component πŸŽ‰ v2.0.0-alpha now open!

An image download extension of the image view written in Swift for iOS, tvOS and macOS.
An image download extension of the image view written in Swift for iOS, tvOS and macOS.

Moa, an image downloader written in Swift for iOS, tvOS and macOS Moa is an image download library written in Swift. It allows to download and show an

πŸ“· A composable image editor using Core Image and Metal.
πŸ“· A composable image editor using Core Image and Metal.

Brightroom - Composable image editor - building your own UI Classic Image Editor PhotosCrop Face detection Masking component πŸŽ‰ v2.0.0-alpha now open!

AsyncImage before iOS 15. Lightweight, pure SwiftUI Image view, that displays an image downloaded from URL, with auxiliary views and local cache.

URLImage URLImage is a SwiftUI view that displays an image downloaded from provided URL. URLImage manages downloading remote image and caching it loca

Comments
  • Ability to remove the background

    Ability to remove the background

    First of all, thank you for this repository. I'm having an issue related to after crop. If the CGShapeLayer is smaller than the imageView of the original image, the outside parts are transparent, and after the following code, I couldn't remove the background either, and select the smallest section of the image.

        func cropImage() {
            if path.isEmpty {
                return
            }
            
            shapeLayer.fillColor = UIColor.black.cgColor
            viewSource.imageView.layer.mask = shapeLayer
            viewSource.imageView.layer.masksToBounds = true
    
            UIGraphicsBeginImageContextWithOptions(viewSource.imageView.bounds.size, false, UIScreen.main.scale)
            viewSource.imageView.layer.render(in: UIGraphicsGetCurrentContext()!)
            let newImage = UIGraphicsGetImageFromCurrentImageContext()
            UIGraphicsEndImageContext()
    
            self.completionObservable.onNext(newImage)
        }
    

    If I add this newImage to another imageview and show it, I still see the transparent layers and not just the cropped area itself.

    Example:

    simulator screen shot - iphone xr - 2019-02-25 at 00 53 47

    enhancement 
    opened by anonrig 2
  • Crop with AI

    Crop with AI

    What if I want to crop the image with some artificial intelligence as in your example some outer part of the car is also cropped along with the the image that we want to crop.That remaining part should be trimmed and if I want to touch on the parts of the car like I don't want to drag my finger along the boundry of the image because in that case some part of the outer image will also be cropped so it there should be some way to select the part of the image to be cropped with some intelligence

    opened by WaqarKhalid 1
  • Better README

    Better README

    Hey @ZaidPathan, your lib is awesome but your README lacks information. I created this iOS README template to help you out πŸ˜‰

    Please fix this issue before we can approve the AwesomeiOS PR

    opened by lfarah 0
  • resetCrop does not reset paths

    resetCrop does not reset paths

    I initialize a ZImageCropperView object as follow.

    lazy var imageView: ZImageCropperView = {
      let v = ZImageCropperView()
      v.translatesAutoresizingMaskIntoConstraints = false
      v.isCropEnabled = true
      v.isUserInteractionEnabled = true
      v.strokeColor = UIColor.systemOrange
      return v
    }()
    

    Users can then draw on the image view. Upon clicking a UIButton, the following @objc function is invoked to reset the crop.

    @objc func resetCrop(sender: UIButton) {
      imageView.resetCrop()
    }
    

    I expect the paths previously drawn by users will be reset upon invoking resetCrop on the image view object. However the paths remain. Is there method other than resetCrop to be called in order to clean all the drawn paths by users? Thanks.


    Edit 1: Additional info: I tested in simulator (iOS 14.4). The UIImage in the image view is loaded via Kingfisher:

    let url = "some_image_url"
    imageView.kf.setImage(with: URL(string: url))
    
    opened by manfredcml 0
Releases(v0.1.1)
Owner
Mohammad Zaid Pathan
Technical Project Manager
Mohammad Zaid Pathan
βœ‚οΈ Detect and crop faces, barcodes and texts in image with iOS 11 Vision api.

ImageDetect ImageDetect is a library developed on Swift. With ImageDetect you can easily detect and crop faces, texts or barcodes in your image with i

Arthur Sahakyan 299 Dec 17, 2022
Image picker with custom crop rect for iOS written in Swift (Ported over from GKImagePicker)

WDImagePicker Ever wanted a custom crop area for the UIImagePickerController? Now you can have it with WDImagePicker. Just set your custom crop area a

Wu Di 96 Dec 19, 2022
Crop faces, inside of your image, with iOS 11 Vision api.

FaceCropper Requirements Xcode 9.0 (beta) or higher. iOS 11.0 (beta) or higher. (It is possible to import this library under the iOS 11. But it won't

Taejun Kim 488 Dec 17, 2022
Simple image crop library for iOS

PhotoCropper This is a simple image crop library for iOS I made for fun on Chris

Aaron Lee 5 Jun 21, 2022
A simplest & base on protocol & swifty way to browse photo or video with hero animation.

JFHeroBrowser Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation JFHe

ι€Έι£Ž 22 Dec 19, 2022
CachedAsyncImage is the simplest way to add cache to your AsyncImage.

SwiftUI CachedAsyncImage ??️ CachedAsyncImage is AsyncImage, but with cache capabilities. Usage CachedAsyncImage has the exact same API and behavior a

Lorenzo Fiamingo 278 Jan 5, 2023
A complete Mac App: drag an image file to the top section and the bottom section will show you the text of any QRCodes in the image.

QRDecode A complete Mac App: drag an image file to the top section and the bottom section will show you the text of any QRCodes in the image. QRDecode

David Phillip Oster 2 Oct 28, 2022
A view controller for iOS that allows users to crop portions of UIImage objects

TOCropViewController TOCropViewController is an open-source UIViewController subclass to crop out sections of UIImage objects, as well as perform basi

Tim Oliver 4.4k Jan 1, 2023
Autocrop - A face-aware crop utility using OSX's Vision framework

autocrop A high-performance face-aware crop utility using OSX's Vision framework

Alex Dong 0 Jan 19, 2022
A crop, compression, resize and trimming library for videos, based on AVKit.

VideoKit VideoKit is a high level layer on top of AVKit How it works // With this config, the video will get resized to 1920x1080p, the maximal length

Knoggl 9 Dec 24, 2022