{"id":15037950,"url":"https://github.com/canhub/android-image-cropper","last_synced_at":"2025-05-14T02:04:55.041Z","repository":{"id":37041503,"uuid":"314844143","full_name":"CanHub/Android-Image-Cropper","owner":"CanHub","description":"Image Cropping Library for Android, optimised for Camera / Gallery.","archived":false,"fork":false,"pushed_at":"2025-03-04T09:37:53.000Z","size":13476,"stargazers_count":1362,"open_issues_count":16,"forks_count":275,"subscribers_count":17,"default_branch":"main","last_synced_at":"2025-04-11T00:42:35.074Z","etag":null,"topics":["android","android-image-crop","android-image-cropper","android-library","camera","canhub","cropper","gallery","hacktoberfest","kotlin"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CanHub.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["canato","vanniktech"]}},"created_at":"2020-11-21T15:37:00.000Z","updated_at":"2025-04-08T07:32:28.000Z","dependencies_parsed_at":"2024-01-16T23:30:26.052Z","dependency_job_id":"6fb254d0-43da-49b3-9882-325810ea9cc6","html_url":"https://github.com/CanHub/Android-Image-Cropper","commit_stats":{"total_commits":235,"total_committers":51,"mean_commits":4.607843137254902,"dds":0.6042553191489362,"last_synced_commit":"78139067b5d6fe3df5ad17281a7f269fa5c133ea"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CanHub%2FAndroid-Image-Cropper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CanHub%2FAndroid-Image-Cropper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CanHub%2FAndroid-Image-Cropper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CanHub%2FAndroid-Image-Cropper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CanHub","download_url":"https://codeload.github.com/CanHub/Android-Image-Cropper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254052692,"owners_count":22006716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-image-crop","android-image-cropper","android-library","camera","canhub","cropper","gallery","hacktoberfest","kotlin"],"created_at":"2024-09-24T20:36:27.579Z","updated_at":"2025-05-14T02:04:54.998Z","avatar_url":"https://github.com/CanHub.png","language":"Kotlin","readme":"[![CanHub](.documentation/art/cover.png?raw=true)](https://github.com/canhub)\n\nAndroid Image Cropper\n=====================\n\n- **Powerful** (Zoom, Rotation, Multi-Source)\n- **Customizable** (Shape, Limits, Style)\n- **Optimized** (Async, Sampling, Matrix)\n- **Simple** image cropping library for Android\n\n![Crop demo](.documentation/art/showcase-1.gif?raw=true)\n\n## Add to your project\n\n```groovy\ndependencies {\n  implementation(\"com.vanniktech:android-image-cropper:4.6.0\")\n}\n```\n\n## Using the Library\n\nThere are 3 ways of using the library. Check out the sample app for all details.\n\n### [1. Calling crop directly](./sample/src/main/kotlin/com/canhub/cropper/sample/SampleCropFragment.kt)\n\n**Note:** This way is deprecated and will be removed in future versions. The path forward is to write your own Activity, handle all the `Uri` stuff yourself and use `CropImageView`.\n\n```kotlin\nclass MainActivity : AppCompatActivity() {\n  private val cropImage = registerForActivityResult(CropImageContract()) { result -\u003e\n    if (result.isSuccessful) {\n      // Use the cropped image URI.\n      val croppedImageUri = result.uriContent\n      val croppedImageFilePath = result.getUriFilePath(this) // optional usage\n      // Process the cropped image URI as needed.\n    } else {\n      // An error occurred.\n      val exception = result.error\n      // Handle the error.\n    }\n  }\n\n  private fun startCrop() {\n    // Start cropping activity with guidelines.\n    cropImage.launch(\n      CropImageContractOptions(\n        cropImageOptions = CropImageOptions(\n          guidelines = Guidelines.ON\n        )\n      )\n    )\n\n    // Start cropping activity with gallery picker only.\n    cropImage.launch(\n      CropImageContractOptions(\n        pickImageContractOptions = PickImageContractOptions(\n          includeGallery = true,\n          includeCamera = false\n        )\n      )\n    )\n\n    // Start cropping activity for a pre-acquired image with custom settings.\n    cropImage.launch(\n      CropImageContractOptions(\n        uri = imageUri,\n        cropImageOptions = CropImageOptions(\n          guidelines = Guidelines.ON,\n          outputCompressFormat = Bitmap.CompressFormat.PNG\n        )\n      )\n    )\n  }\n\n  // Call the startCrop function when needed.\n}\n```\n\n### [2. Using CropView](./sample/src/main/kotlin/com/canhub/cropper/sample/SampleUsingImageViewFragment.kt)\n\n**Note:** This is the only way forward, add `CropImageView` into your own activity and do whatever you wish. Checkout the sample for more details.\n\n```xml\n\u003c!-- Image Cropper fill the remaining available height --\u003e\n\u003ccom.canhub.cropper.CropImageView\n  android:id=\"@+id/cropImageView\"\n  android:layout_width=\"match_parent\"\n  android:layout_height=\"0dp\"\n  android:layout_weight=\"1\"\n  /\u003e\n```\n\n- Set image to crop\n\n```kotlin\ncropImageView.setImageUriAsync(uri)\n// Or prefer using uri for performance and better user experience.\ncropImageView.setImageBitmap(bitmap)\n```\n\n- Get cropped image\n\n```kotlin\n// Subscribe to async event using cropImageView.setOnCropImageCompleteListener(listener)\ncropImageView.getCroppedImageAsync()\n// Or.\nval cropped: Bitmap = cropImageView.getCroppedImage()\n```\n\n### [3. Extend to make a custom activity](./sample/src/main/kotlin/com/canhub/cropper/sample/SampleCustomActivity.kt)\n\n**Note:** This way is also deprecated and will be removed in future versions. The path forward is to write your own Activity, handle all the `Uri` stuff yourself and use `CropImageView`.\n\nIf you want to extend the `CropImageActivity` please be aware you will need to set up your `CropImageView`\n\n- Add `CropImageActivity` into your AndroidManifest.xml\n```xml\n\u003c!-- Theme is optional and only needed if default theme has no action bar. --\u003e\n\u003cactivity\n  android:name=\"com.canhub.cropper.CropImageActivity\"\n  android:theme=\"@style/Base.Theme.AppCompat\"\n  /\u003e\n```\n\n- Set up your `CropImageView` after call `super.onCreate(savedInstanceState)`\n\n```kotlin\noverride fun onCreate(savedInstanceState: Bundle?) {\n  super.onCreate(savedInstanceState)\n  setCropImageView(binding.cropImageView)\n}\n```\n\n#### Custom dialog for image source pick\n\nWhen calling crop directly the library will prompt a dialog for the user choose between gallery or camera (If you keep both enable).\nWe use the Android default AlertDialog for this. If you wanna customised it with your app theme you need to override the method `showImageSourceDialog(..)` when extending the activity _(above)_\n\n```kotlin\noverride fun showImageSourceDialog(openSource: (Source) -\u003e Unit) {\n  super.showImageSourceDialog(openCamera)\n}\n```\n\n## Posts\n\n - [Android cropping image from camera or gallery](https://canato.medium.com/android-cropping-image-from-camera-or-gallery-fbe732800b08)\n\n## Migrating from Android Image Cropper\n\nStart by using [Version 4.3.3](https://github.com/CanHub/Android-Image-Cropper/releases/tag/4.3.3):\n\n```groovy\ndependencies {\n  implementation(\"com.vanniktech:android-image-cropper:4.3.3\")\n}\n```\n\n### Update all imports\n\n```diff\n-import com.theartofdev.edmodo.cropper.CropImage\n-import com.theartofdev.edmodo.cropper.CropImageActivity\n+import com.canhub.cropper.CropImage\n+import com.canhub.cropper.CropImageActivity\n```\n\n### Update all XML references\n\n```diff\n-\u003ccom.theartofdev.edmodo.cropper.CropImageView\n+\u003ccom.canhub.cropper.CropImageView\n```\n\nWhen using Activity Contracts, consult with the sample app on how to use our Activity Contracts since `onActivityResult` got deprecated.\n\nVersions after 4.3.3 have changed the APIs quite a bit, it's best to upgrade to each minor version individually, remove deprecated API usages and continue upgrading. So after using 4.3.3, upgrade to 4.4.0, upgrade to 4.5.0, 4.6.0, etc.\n\n## License\n\nForked from [ArthurHub](https://github.com/ArthurHub/Android-Image-Cropper)\nOriginally forked from [edmodo/cropper](https://github.com/edmodo/cropper).\n\nCopyright 2016, Arthur Teplitzki, 2013, Edmodo, Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this work except in compliance with the   License.\nYou may obtain a copy of the License in the LICENSE file, or at:\n\n  http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS   IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n","funding_links":["https://github.com/sponsors/canato","https://github.com/sponsors/vanniktech"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcanhub%2Fandroid-image-cropper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcanhub%2Fandroid-image-cropper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcanhub%2Fandroid-image-cropper/lists"}