Giter Club home page Giter Club logo

coil-transformations's Introduction

coil-transformations

Image transformations for Coil.

Download

Add this in your root build.gradle file (not your module build.gradle file):

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

Then, add the library to your app build.gradle

implementation("com.github.Commit451.coil-transformations:transformations:latest.version.here")

and for GPU (native) transformations (relies on GPUImage):

implementation("com.github.Commit451.coil-transformations:transformations-gpu:latest.version.here")

and for Google MLKit Face detection transformations:

implementation("com.github.Commit451.coil-transformations:transformations-face-detection:latest.version.here")

Supported Transformations

These transformations are already supported in Coil itself (no need for this library):

  • CircleCropTransformation
  • RoundedCornersTransformation

From the base library (transformations):

  • BlurTransformation
  • ColorFilterTransformation
  • CropTransformation (top, center, bottom)
  • GrayscaleTransformation
  • MaskTransformation
  • SquareCropTransformation

From the GPU library (transformations-gpu)

  • BrightnessFilterTransformation
  • ContrastFilterTransformation
  • InvertFilterTransformation
  • KuwaharaFilterTransformation
  • PixelationFilterTransformation
  • SepiaFilterTransformation
  • SketchFilterTransformation
  • SwirlFilterTransformation
  • ToonFilterTransformation
  • VignetteFilterTransformation

From the face detection library (transformations-center-on-face)

  • CenterOnFaceTransformation

Quick Start

To load an image into an ImageView with transformations, use the load extension function:

imageView.load("https://www.example.com/image.jpg") {
    transformations(BlurTransformation(), CircleCropTransformation()) // You can add as many as desired
}

Preview

See a preview of the transformations here

Thanks

Inspired by Glide Transformations by wasabeef. Thanks of course to Coil contributors for making a great image loading library.

License

Copyright 2022 Commit 451

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

   https://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.

coil-transformations's People

Contributors

bonepeople avatar brady-aiello avatar jawnnypoo avatar xanscale avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

coil-transformations's Issues

new transformations

 class FitWidthCrop : Transformation {

        override val cacheKey: String = javaClass.name

        override suspend fun transform(input: Bitmap, size: Size): Bitmap {
            val srcWidth: Int = input.width
            val srcHeight: Int = input.height
            val (outputWidth, outputHeight) = calculateOutputSize(input, size)
            val sR = srcHeight.toFloat().div(srcWidth)
            val oR = outputHeight.toFloat().div(outputWidth)
            if (sR <= oR) {
                return input
            }
            val scale = srcWidth.toFloat().div(outputWidth)
            val newOutputHeight = outputHeight.times(scale).roundToInt()
            val y = srcHeight.minus(newOutputHeight).div(2)
            return Bitmap.createBitmap(input, 0, y, srcWidth, newOutputHeight)
        }

        override fun equals(other: Any?) = other is CircleCropTransformation

        override fun hashCode() = javaClass.hashCode()

        private fun calculateOutputSize(input: Bitmap, size: Size): Pair<Int, Int> {
            if (size.isOriginal) {
                return input.width to input.height
            }

            val (dstWidth, dstHeight) = size
            if (dstWidth is Dimension.Pixels && dstHeight is Dimension.Pixels) {
                return dstWidth.px to dstHeight.px
            }

            val multiplier = DecodeUtils.computeSizeMultiplier(
                srcWidth = input.width,
                srcHeight = input.height,
                dstWidth = size.width.pxOrElse { Int.MIN_VALUE },
                dstHeight = size.height.pxOrElse { Int.MIN_VALUE },
                scale = Scale.FILL
            )
            val outputWidth = (multiplier * input.width).roundToInt()
            val outputHeight = (multiplier * input.height).roundToInt()
            return outputWidth to outputHeight
        }
    }

CropTransformation not cropping

hi,

i just tested the crop transformation and i get the same result for type top, center and bottom. also nothing gets cropped
image

i apply them like this
binding.image.load(url){transformations(CropTransformation(CropTransformation.CropType.TOP)) }

coil version is 2.5.0
lib version is 2.0.2

lg

Face Detection Transformation not in any library

Hi,
I would like to know which library to import for Face Detection Transformation. It is not currently in any given libraries and I can't find any face detection separate library on jitpack.

Transformations from base library and GPU library don't load

Hi, i can apply transformations that are already supported in Coil itself well, but when i try to load from the base library (transformations) and from GPU library the picture is not loaded

                    image.load("url_pic") {
                        transformations(VignetteFilterTransformation(applicationContext))
                    }

Tested with Android 6.0.1

Adding BlurTransformation that was removed in Coil 2.0

Coil 2.0 alpha has BlurTransformation removed from the library.
The authors recommend copy-pasting source code to the project for those who relied on it, however BlurTransformation used deprecated APIs and internal methods heavily, many of which were removed, essentially making this advice impossible to follow.

It would be nice to have this library add an updated version of BlurTransformation and GrayscaleTransformation to help those who relied on them before.

[Security] Repository is vulnerable to MavenGate

https://blog.oversecured.com/Introducing-MavenGate-a-supply-chain-attack-method-for-Java-and-Android-applications/

Gradle task

./gradlew --write-verification-metadata pgp,sha256 --export-keys
 <component group="com.github.Commit451.coil-transformations" name="transformations" version="2.0.2">
         <artifact name="transformations-2.0.2.aar">
            <sha256 value="adbec226ce2c3a78b5e242e960971649b502cf3274aae421c48edd6bb94c7f56" origin="Generated by Gradle" reason="Artifact is not signed"/>
         </artifact>
         <artifact name="transformations-2.0.2.module">
            <sha256 value="58392a2a62b37ea8289a4633f9e4566c84ba5637806e6abbba87f14fac081aa4" origin="Generated by Gradle" reason="Artifact is not signed"/>
         </artifact>
      </component>

did not find a pgp public key in a remote repository or the artifact is not signed.
A fix is to:

  1. Start signing all artifacts, if not signed yet
  2. Upload a public pgp key used for signing artifacts to multiple public pgp repositories: https://keys.openpgp.org | https://pgp.mit.edu | https://keyserver.ubuntu.com/

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.