Achieve Instagram-like Image Cropping with "InstaCropper"

Introduction:

"InstaCropper" is an open-source GitHub project designed for implementing image cropping functionality similar to Instagram in Android applications. It utilizes Kotlin and Jetpack Compose, making it incredibly simple and user-friendly.

Key Features:

  • Supports various cropping ratios, including 1:1, 16:9, 4:3, and more.
  • Supports saving cropped images locally.
  • Supports sharing cropped images on social media platforms.

How to Use:

Integrating "InstaCropper" into your Android application is straightforward. Simply add the following dependency:

dependencies {
    implementation 'com.yashoid:instacropper:1.2.0'
}

Here's an example code snippet:

// Create a cropper
val cropper = InstaCropperView(requireContext())

// Set the image
cropper.setImageResource(R.drawable.image)

// Set the cropping ratio
cropper.setRatios(1, 1)

// Show the cropper
cropper.show()

// Callback after cropping
cropper.onCropped { bitmap ->
    // Save the cropped image
    // ...

    // Share the cropped image
    // ...
}

After running this example, a cropper will appear. You can drag the cropping frame to select the desired crop area and then click the "Complete" button to finish cropping.

"InstaCropper" also supports customizing the cropper's style. You can modify the style property to set the background color, text color, font weight, and more.

Here are some example code snippets:

// Set the background color to yellow, text color to black, and font weight to normal
cropper.style = ComposeCropperStyle(
    background = Color.Yellow,
    textColor = Color.Black,
    fontWeight = FontWeight.Normal,
)

// Set the background color to red, text color to white, and font weight to bold
cropper.style = ComposeCropperStyle(
    background = Color.Red,
    textColor = Color.White,
    fontWeight = FontWeight.Bold,
)

Conclusion:

"InstaCropper" is an incredibly user-friendly image cropping tool that allows you to quickly implement Instagram-like image cropping functionality in your Android application.