Coder Social home page Coder Social logo

morristech / imagepicker-10 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from drjacky/imagepicker

0.0 0.0 0.0 32.49 MB

📸Image Picker for Android, Pick an image from Gallery or Capture a new image with Camera🖼

Home Page: https://github.com/Drjacky/ImagePicker

License: Apache License 2.0

Kotlin 100.00%

imagepicker-10's Introduction

📸Image Picker Library for Android

Releases API Language PRWelcome FOSSA Status Android Arsenal Language

Easy to use and configurable library to Pick an image from the Gallery or Capture image using Camera. It also allows to Crop the Image based on Aspect Ratio, Resolution and Image Size.

‍🏍Features

  • Pick Gallery Image
  • Pick Image from Google Drive
  • Capture Camera Image
  • Crop Image(Crop image based on provided aspect ratio or let user choose one)
  • Compress Image(Compress image based on provided resolution and size)
  • Retrieve Image Result as File, File Path as String or Uri object
  • Handle Runtime Permission for Camera and Storage

🎬Preview

Profile Image Picker Gallery Only Camera Only

💻Usage

Gradle dependency:

	allprojects {
	   repositories {
	      	mavenCentral() // For ImagePicker library, this line is enough. Although, it has been published on jitpack as well
           	maven { url "https://jitpack.io" }  //Make sure to add this in your project for uCrop - an internal library
	   }
	}
   implementation 'com.github.Drjacky:ImagePicker:$libVersion'

Where $libVersion = libVersion

If you want to get the activity result:

Kotlin

   private val launcher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
       if (it.resultCode == Activity.RESULT_OK) {
           val uri = it.data?.data!!
           // Use the uri to load the image
       }
   }

Java

   ActivityResultLauncher<Intent> launcher =
               registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), (ActivityResult result) -> {
                   if (result.getResultCode() == RESULT_OK) {
                       Uri uri = result.getData().getData();
                       // Use the uri to load the image
                   } else if (result.getResultCode() == ImagePicker.RESULT_ERROR) {
                       // Use ImagePicker.Companion.getError(result.getData()) to show an error
                   }
               });

If you want both Camera and Gallery:

Kotlin

    ImagePicker.with(this)
       //...
       .createIntentFromDialog { launcher.launch(it) }

Java

   ImagePicker.Companion.with(this)
                       .crop()
                       .cropOval()
                       .maxResultSize(512, 512, true)
                       .createIntentFromDialog((Function1) (new Function1() {
                           public Object invoke(Object var1) {
                               this.invoke((Intent) var1);
                               return Unit.INSTANCE;
                           }

                           public final void invoke(@NotNull Intent it) {
                               Intrinsics.checkNotNullParameter(it, "it");
                               launcher.launch(it);
                           }
                       }));

If you want just one option:

Kotlin

    launcher.launch(
       ImagePicker.with(this)
           //...
           .cameraOnly() // or galleryOnly()
           .createIntent()
    )

Java

        ImagePicker.Companion.with(this)
                .crop()	    			//Crop image(Optional), Check Customization for more option
                .cropOval()	    		//Allow dimmed layer to have a circle inside
                .galleryOnly()          //We have to define what image provider we want to use
                .maxResultSize(1080, 1080)	//Final image resolution will be less than 1080 x 1080(Optional)
                .createIntent()

🎨Customization

  • Pick image using Gallery

    ImagePicker.with(this)
    	.galleryOnly()	//User can only select image from Gallery
    	.createIntent()	//Default Request Code is ImagePicker.REQUEST_CODE
  • Capture image using Camera

    ImagePicker.with(this)
    	.cameraOnly()	//User can only capture image using Camera
    	.createIntent()
  • Crop image

    ImagePicker.with(this)
    	.crop()	    //Crop image and let user choose aspect ratio.
    	.createIntent()
  • Crop image with fixed Aspect Ratio

    ImagePicker.with(this)
    	.crop(16f, 9f)	//Crop image with 16:9 aspect ratio
    	.createIntent()
  • Crop square image(e.g for profile)

     ImagePicker.with(this)
         .cropSquare()	//Crop square image, its same as crop(1f, 1f)
         .createIntent()
  • Compress image size(e.g image should be maximum 1 MB)

    ImagePicker.with(this)
    	.createIntent()
  • Set Resize image resolution

    ImagePicker.with(this)
    	.maxResultSize(620, 620)	//Final image resolution will be less than 620 x 620
    	.createIntent()
  • Intercept ImageProvider, Can be used for analytics

    ImagePicker.with(this)
        .setImageProviderInterceptor { imageProvider -> //Intercept ImageProvider
            Log.d("ImagePicker", "Selected ImageProvider: "+imageProvider.name)
        }
        .createIntent()
  • Intercept Dialog dismiss event

    ImagePicker.with(this)
    	.setDismissListener {
    		// Handle dismiss event
    		Log.d("ImagePicker", "onDismiss");
    	}
    	.createIntent()
  • Limit MIME types while choosing a gallery image

    ImagePicker.with(this)
        .galleryMimeTypes(  //Exclude gif images
            mimeTypes = arrayOf(
              "image/png",
              "image/jpg",
              "image/jpeg"
            )
          )
        .createIntent()
  • You can also specify the request code with ImagePicker

    ImagePicker.with(this)
    	.maxResultSize(620, 620)
    	.start(101)	//Here 101 is request code, you may use this in onActivityResult
  • Add Following parameters in your colors.xml file, If you want to customize uCrop Activity.

    <resources>
        <!-- Here you can add color of your choice  -->
        <color name="ucrop_color_toolbar">@color/teal_500</color>
        <color name="ucrop_color_statusbar">@color/teal_700</color>
        <color name="ucrop_color_widget_active">@color/teal_500</color>
    </resources>

💥Compatibility

  • Library - Android Kitkat 4.4+ (API 19)
  • Sample - Android Kitkat 4.4+ (API 19)

📃 Libraries Used

License

FOSSA Status

imagepicker-10's People

Contributors

benjaminlefevre avatar dhaval2404 avatar douglas-srs avatar drjacky avatar fossabot avatar marchuck avatar mdxdave avatar soareseneves avatar terence-codigo avatar yamin8000 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.