项目介绍

zetbaitsu/Compressor 是一个托管在 GitHub 上的开源项目,主要使用 Kotlin 编写,目前获得 7.2k 个 Star、962 次 Fork。

仓库全名
zetbaitsu/Compressor
Star 数
7.2k
Fork 数
962
未关闭 Issue
140

README 摘要

Compressor ====== Compressor is a lightweight and powerful android image compression library. Compressor will allow you to compress large photos into smaller sized photos with very less or negligible loss in quality of the image. Gradle Let's compress the image size! Compress Image File Compress Image File to specific destination I want custom Compressor! Using default constraint and custom partial of it Full custom…

完整内容见 GitHub 原始 README 或本页 。

常见问题

Compressor 用什么语言开发?

主要使用 Kotlin 编写,目前有 7.2k 个 Star。

如何获取 Compressor 的源码?

可以直接克隆仓库:git clone https://github.com/zetbaitsu/Compressor.git,默认分支为 master;安装与运行步骤见仓库 README。

Compressor 最近还在维护吗?

仓库最近一次更新为 3月5日,当前有 140 个未关闭 Issue;Star 数为 7.2k,可作为社区活跃度的参考。

语言占比

Java
Kotlin

Release

README

Compressor

Android Arsenal Build Status codecov

Compressor is a lightweight and powerful android image compression library. Compressor will allow you to compress large photos into smaller sized photos with very less or negligible loss in quality of the image.

Gradle

dependencies {
    implementation 'id.zelory:compressor:3.0.1'
}

Let’s compress the image size!

Compress Image File
val compressedImageFile = Compressor.compress(context, actualImageFile)
Compress Image File to specific destination
val compressedImageFile = Compressor.compress(context, actualImageFile) {
    default()
    destination(myFile)
}

I want custom Compressor!

Using default constraint and custom partial of it
val compressedImageFile = Compressor.compress(context, actualImageFile) {
    default(width = 640, format = Bitmap.CompressFormat.WEBP)
}
Full custom constraint
val compressedImageFile = Compressor.compress(context, actualImageFile) {
    resolution(1280, 720)
    quality(80)
    format(Bitmap.CompressFormat.WEBP)
    size(2_097_152) // 2 MB
}
Using your own custom constraint
class MyLowerCaseNameConstraint: Constraint {
    override fun isSatisfied(imageFile: File): Boolean {
        return imageFile.name.all { it.isLowerCase() }
    }

    override fun satisfy(imageFile: File): File {
        val destination = File(imageFile.parent, imageFile.name.toLowerCase())
        imageFile.renameTo(destination)
        return destination
    }
}

val compressedImageFile = Compressor.compress(context, actualImageFile) {
    constraint(MyLowerCaseNameConstraint()) // your own constraint
    quality(80) // combine with compressor constraint
    format(Bitmap.CompressFormat.WEBP)
}
You can create your own extension too
fun Compression.lowerCaseName() {
    constraint(MyLowerCaseNameConstraint())
}

val compressedImageFile = Compressor.compress(context, actualImageFile) {
    lowerCaseName() // your own extension
    quality(80) // combine with compressor constraint
    format(Bitmap.CompressFormat.WEBP)
}

Compressor now is using Kotlin coroutines!

Calling Compressor should be done from coroutines scope
// e.g calling from activity lifecycle scope
lifecycleScope.launch {
    val compressedImageFile = Compressor.compress(context, actualImageFile)
}

// calling from global scope
GlobalScope.launch {
    val compressedImageFile = Compressor.compress(context, actualImageFile)
}
Run Compressor in main thread
val compressedImageFile = Compressor.compress(context, actualImageFile, Dispatchers.Main)

Old version

Please read this readme

License

Copyright (c) 2016 Zetra.

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.

评论

暂无评论