Android Gradle Plugin -- Auto Check big image and compress image in building.
APACHE-2.0 License
我会持续更新,请大家放心使用,Bug也会及时跟进
McImage是无侵入式的全量压缩资源图片插件
包括
插件使用算法
1.0.1版本现在支持全版本的build.gradle脚本! 最近版本已经支持mavenCentral()
v0.0.2以后的用户更新到0.0.2以上需要升级你的mctools文件夹,已经上传到release。
如果你使用McImage,我可以把你的icon放在这里并且加上一个链接~ 发到我的邮箱[email protected]并备注mcimage即可
PS:目前我司项目正在使用此仓库进行压缩
首先,修改你根目录的build.gradle.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.smallsoho.mobcase:McImage:1.5.1'
}
}
然后在你想要压缩的Module的build.gradle中应用这个插件,注意如果你有多个Module,请在每个Module的build.gradle文件中apply插件
apply plugin: 'McImage'
最后将我代码中的mctools文件夹放到项目根目录,此文件在这里下载
mctools
你可以在build.gradle中配置插件的几个属性,如果不设置,所有的属性都使用默认值
McImageConfig {
isCheckSize true //是否检测图片大小,默认为true
optimizeType "Compress" //优化类型,可选"ConvertWebp","Compress",转换为webp或原图压缩,默认Compress,使用ConvertWep需要min sdk >= 18.但是压缩效果更好
maxSize 1*1024*1024 //大图片阈值,default 1MB
enableWhenDebug false //debug下是否可用,default true
isCheckPixels true // 是否检测大像素图片,default true
maxWidth 1000 //default 1000 如果开启图片宽高检查,默认的最大宽度
maxHeight 1000 //default 1000 如果开启图片宽高检查,默认的最大高度
whiteList = [ //默认为空,如果添加,对图片不进行任何处理
"icon_launcher.png"
]
mctoolsDir "$rootDir"
isSupportAlphaWebp false //是否支持带有透明度的webp,default false,带有透明图的图片会进行压缩
multiThread true //是否开启多线程处理图片,default true
bigImageWhiteList = [] //默认为空,如果添加,大图检测将跳过这些图片
}
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.