Giter Site home page Giter Site logo

imagecompressiondemo's Introduction

ImageCompressionDemo

Custom Image Picker Controller - singular object prevents pollution in a UIViewController.

Use this custom object to delegate, compress quality, and perform an action with images in iOS. Comments in code can be used to understand how things are done.

Example usage:

Addition of an compression quality enum:

enum JPEGCompressionQualityRate: CGFloat {
    case lowest  = 0
    case low     = 0.25
    case medium  = 0.5
    case high    = 0.75
    case highest = 1
    
    case profilePicture = 0.2 // an example of a default compression setting that may be applicable.
}

Configuring each picker:

picker1 = ImageCompressionPicker(for: self, compressionQualityRate: .lowest, action: { (image) in
            
/*
 IMPORTANT: In here ^^^, we would begin to perform any type of transaction for the image.
 Example: Uploading it to a server or storing on a device.
 When we store these types of data, we have the option of uploading the ImageData object itself, or we may convert it to a UIImage and then proceed.
 --- We would just need to change the ImagePickerAction handle.
*/

            print("action for picker 1")
            self.imageView.image = image
            print(image.debugDescription)
})

picker2 = ImageCompressionPicker(for: self, compressionQualityRate: .lowest, action: { (image) in

/*
 IMPORTANT: In here ^^^, we would begin to perform any type of transaction for the image.
 Example: Uploading it to a server or storing on a device.
 When we store these types of data, we have the option of uploading the ImageData object itself, or we may convert it to a UIImage and then proceed.
 --- We would just need to change the ImagePickerAction handle.
*/

            print("action for picker 2")
            self.imageView.image = image
            print(image.debugDescription)
})

Presenting:

//example of a request to change picture through the user interface.
@IBAction func button1DidTap(_ sender: Any) {
            if let picker = picker1{
              picker.presentAlert()
            } else{
                         //error handeling
                        //fatalAsset() ---> because init(){} must be used.
            }
}

imagecompressiondemo's People

Contributors

baksha97 avatar

Watchers

James Cloos 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.