Skip to content

devvura/safe-image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

39 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Safe Image

Maven Central Version Maven Central Version

Safe Image Banner

๐Ÿ“– Description

Safe Image is an AI-powered image filtering library designed to promote safe and culturally appropriate content.
The library uses advanced deep learning models to automatically detect and blur inappropriate or sensitive content in images, with full control over the blur strength, ensuring that visuals remain respectful and aligned with Islamic values.

Sensitive Content Sample

๐Ÿš€ How to Use

Installation

Make sure Maven Central is added to your project-level build.gradle (or settings.gradle for Gradle 7+):

repositories {
    google()
    mavenCentral()
}

1. Jetpack Compose Usage

Add Safe Image in module-level build.gradle:

dependencies {
    implementation("io.github.devvura:safe-image-compose:1.0.0")
}

Minimal Usage

If you only want to display an image with automatic blurring, you can use SafelImage with just the model parameter:

SafeImage(
    model = "https://example.com/sample.jpg",
    contentDescription = "Sample Image"
)

Customizable Usage

You can fully customize SafeImage by providing parameters such as loadingContent, errorContent, onBlurContent, blurRadius, and more:

SafeImage(
    modifier = Modifier.fillMaxWidth(),
    model = "https://example.com/sample.jpg",
    contentDescription = "Sample Image",
    loadingContent = { Text(text = "Loading...") },
    errorContent = { Text(text = "Error loading image") },
    onBlurContent = { Text(text = "Sensitive content")},
    blurRadius = 20,
    contentScale = ContentScale.FillWidth
)

Parameters Reference

Parameter Type Default Description
model Any โ€” The image source (URL, file, resource, etc.)
contentDescription String? null Description for accessibility (screen readers)
modifier Modifier Modifier Layout styling (size, padding, etc.)
loadingContent @Composable () -> Unit null UI to display while the image is loading
errorContent @Composable () -> Unit null UI to display if loading fails
onBlurContent @Composable () -> Unit null UI overlay shown when inappropriate content is blurred
blurRadius Int 16 Blur strength applied to blurred images
contentScale ContentScale ContentScale.Crop Defines how the image should scale inside its container

2. XML Usage

Add Safe Image in module-level build.gradle:

dependencies {
    implementation("io.github.devvura:safe-image:1.0.0")
}

Minimal Usage

If you only want to display an image with automatic blurring, you can use SafeImage with just the model parameter:

val imageView = findViewById<ImageView>(R.id.imageView1)
imageView.loadSafeImage(
    model = "https://example.com/sample.jpg",
    placeholderRes = R.drawable.loading_bar,
    errorDrawableRes = R.drawable.error_svgrepo_com
)

Customizable Usage

You can fully customize SafeImage by providing parameters such as onLoading, onError, blurRadius, and more:

val imageView = findViewById<ImageView>(R.id.imageView1)
imageView.loadSafeImage(
    model = "https://example.com/sample.jpg",
    blurRadius = 70,
    onLoading = { 
        Toast.makeText(context, "Loading image...", Toast.LENGTH_SHORT).show() 
    },
    onError = { 
        Toast.makeText(context, "Failed to load image", Toast.LENGTH_SHORT).show() 
    },
    onSuccess = { 
        Toast.makeText(context, "Image loaded successfully!", Toast.LENGTH_SHORT).show() 
    },
    crossFadeEnabled = true,
    placeholderRes = R.drawable.loading_bar,
    errorDrawableRes = R.drawable.error_svgrepo_com
)

Parameters Reference

Parameter Type Default Description
model Any โ€” The image source (URL, file, resource, etc.)
blurRadius Int 50 Blur strength in pixels
onLoading (() -> Unit)? null Callback triggered when image starts loading
onError (() -> Unit)? null Callback triggered if image loading fails
onSuccess (() -> Unit)? null Callback triggered when image loads successfully
crossFadeEnabled Boolean true Enables smooth crossfade animation between placeholder and image
placeholderRes @DrawableRes Int? null Drawable resource displayed while loading
errorDrawableRes @DrawableRes Int? null Drawable resource displayed on error

๐Ÿ› ๏ธ How Does It Work

Safe Image integrates seamlessly with Coilโ€™s image loading pipeline, working specifically on the Transformation step to detect and blur unsafe images before they are displayed.
This ensures maximum performance and that sensitive content never flashes on the screen unblurred.

Coil's Pipeline

When you load an image with Safe Image, it is first passed through Coilโ€™s request pipeline, which includes a custom transformation. This transformation uses an AI-powered detector to analyze the image before it is displayed. If the detector identifies unsafe content, the image is blurred with a configurable blur radius; otherwise, it is shown normally.

Under the hood, the detection is powered by a TensorFlow Lite model trained to distinguish between safe and unsafe content. Each image is resized, normalized, and classified, and if the probability of sensitive content exceeds a threshold, the image is flagged as NSFW.

To ensure smooth performance, Coilโ€™s memory and disk caching are enabled so images are not repeatedly processed.

Safe image flow chart


๐Ÿ“Š Model & Dataset

  • The AI model was trained on a custom dataset consisting of 11,304 images, categorized as either safe or unsafe.
  • The unsafe category includes 5,652 images containing sensitive or explicit content.
  • The safe category also contains 5,652 images, featuring appropriate content such as individuals in everyday attire, including hijabi women, men, and women in normal contexts.
  • To improve generalization and accuracy, the dataset was carefully collected from individuals of diverse nationalities.
  • The trained model achieved an accuracy of 96% on the training set and 94% on the testing set, effectively covering the majority of sensitive content detection cases, with only a few exceptions.
  • The deployed TFLite model size is ~10 MB.
  • Supported image formats: PNG, JPG, JPEG2000, and WEBP.

๐ŸŒ Supported Platforms

Safe Image is built as a Kotlin Multiplatform (KMP) project.
Below are the currently supported targets:

Platform Status Notes
Android (Compose) โœ… Implemented Full support with SafeImage composable
Android (XML Views) โœ… Implemented loadSafeImage extension for ImageView
iOS โณ Not yet implemented Planned for future release
Desktop โณ Not yet implemented Planned for future release
Web โณ Not yet implemented Planned for future release

๐Ÿ”ฎ Future Plans

We are continuously improving Safe Image. Here are some of the planned features and enhancements:

  • Extended Platform Support โ€“ bringing Safe Image to iOS, Desktop, and Web through Kotlin Multiplatform.
  • Smarter AI Model โ€“ improved accuracy with larger and more diverse training datasets.

๐Ÿ™Œ Contributions and suggestions are always welcome!


๐Ÿค Contributors

Safe Image is proudly developed and maintained by:


๐Ÿ“„ License:

Copyright 2025 Team Devura

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless 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

About

AI-powered image filtering library designed to promote safe and culturally appropriate content.

Resources

License

Stars

27 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages