android 图片自动瘦身插件

项目地址

使用

  1. 根目录下build.gradle 中添加依赖
buildscript {
    repositories {
        maven { url 'https://jitpack.io' }
        ...
    }
    dependencies {
        classpath 'com.github.NiLuogege:ImageDeflated:1.0.1'
        ...
    }
}
  1. app的build.gradle 中引用插件并进行配置
apply plugin: 'ImageDeflated'

...


imageDeflated {
    tiny {
        open = true
        key = "xxx填入自己的keyxxx"
        threshold = 1024 * 11
        whiteList = [
                "ic_launcher.png",
                "ic_launcher_round.png",
                "white*.png",
        ]
    }

    webp {
//        artifact = "com.niluogege.tools:cwebp:1.2.0" 
        path = "E:\\libwebp-1.2.0\\bin\\cwebp.exe" 
        open = true
        quality = 80
        whiteList = [
                "ic_launcher.png",
                "ic_launcher_round.png",
                "logo*.png",
        ]
    }
}

需要注意下:
    - tiny 的 key需要自己去[官网](https://tinypng.com/developers)申请。申请后直接替换即可。
    - cwebp 下载地址 https://storage.googleapis.com/downloads.webmproject.org/releases/webp/index.html 我使用的是 `libwebp-1.2.0-windows-x64`
  1. 继承完成 运行 assembleDebug 看效果
    运行完成后会在 app/build/imageDeflated 下输出 record.md 用来记录这次图片的压缩情况。

转载请注明出处,谢谢

你可能感兴趣的:(android 图片自动瘦身插件)