Skip to content

Commit

Permalink
Merge pull request #23 from cyanstone/master_feature_webp
Browse files Browse the repository at this point in the history
Master feature webp
  • Loading branch information
owenlongbo authored Jun 4, 2019
2 parents 2cd91c3 + 767508b commit db77743
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 126 deletions.
30 changes: 17 additions & 13 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ McImage是无侵入式的全量压缩资源图片插件
### Update Log

> v0.0.2以后的用户更新到0.0.2以上需要升级你的mctools文件夹,已经上传到release。
- 1.4.0 : 区分优化类型,可选择ConvertWep或Compress, 默认ConvertWebp,压缩比更高
- 1.3.0 : 支持多线程压缩,缩短执行时间
- 1.2.0 : 优先从系统获取压缩命令, 不存在使用本地文件命令
- 1.0.1 : 修复了maxSize无法使用浮点数的问题
- 1.0.0 : 正式支持了AAPT2,现在不需要使用android.enableAapt2=false关闭了,可以去掉这个flag
Expand All @@ -59,7 +60,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.smallsoho.mobcase:McImage:1.0.1'
classpath 'com.smallsoho.mobcase:McImage:1.4.0'
}
}
```
Expand All @@ -82,17 +83,20 @@ mctools

```groovy
McImageConfig {
isCheck true //default true 是否进行图片大小超标的检查
isCompress true //default true 是否进行图片压缩
maxSize 1*1024*1024 //default 1MB 图片大小超标的标准大小
isWebpConvert true //default true 是否进行对图片的webp处理
isJPGConvert true //default true 是否对jpg进行webp处理
enableWhenDebug true //default true 是否在debug的时候启用插件
isCheckSize true //default true 是否开启图片宽高检查
maxWidth 500 //defualt 500 如果开启图片宽高检查,默认的最大宽度
maxHeight 500 //defualt 500 如果开启图片宽高检查,默认的最大高度
whiteList = [
"drawable-xxhdpi-v4/img_five_stars.png" //默认为空,如果添加,对图片不进行任何处理
isCheckSize true //是否检测图片大小,默认为true
optimizeType "ConertWebp" //优化类型,可选"ConvertWebp","Compress",转换为webp或原图压缩,默认ConvertWebp,压缩比更高
maxSize 1*1024*1024 //大图片阈值,default 1MB
enableWhenDebug false //debug下是否可用,default true
isCheckPixels true // 是否检测大像素图片,default true
maxWidth 1000 //defualt 1000 如果开启图片宽高检查,默认的最大宽度
maxHeight 1000 //defualt 1000 如果开启图片宽高检查,默认的最大高度
whiteList = [ //默认为空,如果添加,对图片不进行任何处理
"icon_launcher.png"
]
mctoolsDir "$rootDir/tools"
isSupportAlphaWebp false //是否支持带有透明度的webp,default false,带有透明图的图片会进行压缩
multiThread true //是否开启多线程处理图片,default true
bigImageWhiteList = [ //默认为空,如果添加,大图检测将跳过这些图片
]
}
```
Expand Down
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ The version 1.0.1 now support all build.gradle version!
### Update Log

> The user use v0.0.2 update plugin need update your mctools dir together.
- 1.4.0 : Featrue, Support for selecting different optimization types,"ConvertWebp" or "Compress" can be chosen.Default "WebpConvert" be Choosen because it has a better compression ratio.
- 1.3.0 : Featrue, Support multi-thread processing
- 1.2.0 : Feature, get compress command from system environment prior to local file
- 1.0.1 : Bug fix, fix maxSize float error
- 1.0.0 : Support AAPT2 , now don't need to close aapt2 with "android.enableAapt2=false", you can delete this line in gradle.properties.
Expand All @@ -59,7 +60,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.smallsoho.mobcase:McImage:1.0.1'
classpath 'com.smallsoho.mobcase:McImage:1.4.0'
}
}
```
Expand All @@ -83,18 +84,21 @@ You can set the config in build.gradle.If you not set this,all config will use d

```groovy
McImageConfig {
isCheck true //default true
isCompress true //default true
maxSize 1*1024*1024 //default 1MB
isWebpConvert true //default true
isJPGConvert true //default true
enableWhenDebug true //default true
isCheckSize true //default true
maxWidth 500 //defualt 500 the default size of check size feature
maxHeight 500 //defualt 500 the default size of check size feature
whiteList = [
"drawable-xxhdpi-v4/img_five_stars.png" //add this line, the plugin can not deal with this img.
]
isCheckSize true //Whether to detect image size,default true
optimizeType "ConertWebp" //Optimize Type,"ConvertWebp" or "Compress",default "ConvertWebp"
maxSize 1*1024*1024 //big image size threshold,default 1MB
enableWhenDebug false //swithc in debug build,default true
isCheckPixels true // Whether to detect image pixels of width and height,default true
maxWidth 1000 //defualt 1000
maxHeight 1000 //defualt 1000
whiteList = [ //do not do any optimization for the images who in the list
"icon_launcher.png"
]
mctoolsDir "$rootDir/tools"
isSupportAlphaWebp false //Whether support convert the Image with Alpha chanel to Webp,default false, the images with alpha chanels will be compressed.if config true, its need api level >=18 or do some compatible measures
multiThread true //Whether open muti-thread processing,default true
bigImageWhiteList = [ //do not detect big size or large pixels for the images who in the list
]
}
```

Expand Down
2 changes: 1 addition & 1 deletion bintray.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'com.jfrog.bintray'
def siteUrl = 'https://github.com/Aweme/McImage'
def gitUrl = 'https://github.com/Aweme/McImage.git'
group = "com.smallsoho.mobcase"
version = "1.3.0"
version = "1.4.0"

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
Expand Down
2 changes: 1 addition & 1 deletion publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'maven'
apply plugin: 'signing'

def DEBUG = true
def VERSION = '1.3.0'
def VERSION = '1.4.0'
def GROUP = 'com.smallsoho.mobcase'
def ARTIFACT = 'McImage'

Expand Down
73 changes: 50 additions & 23 deletions src/main/java/com/smallsoho/mcplugin/image/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,44 @@

public class Config {

public static final String OPTIMIZE_WEBP_CONVERT = "ConvertWebp"; //webp化
public static final String OPTIMIZE_COMPRESS_PICTURE = "Compress"; //压缩图片

public float maxSize = 1024 * 1024;
public boolean isCheck = true;
public boolean isCompress = true;
public boolean isWebpConvert = true;
public boolean isJPGConvert = true;
public boolean isCheckSize = true; //是否检查大体积图片
public String optimizeType = OPTIMIZE_WEBP_CONVERT; //优化方式,webp化、压缩图片
public boolean enableWhenDebug = true;
public boolean isCheckSize = true;
public int maxWidth = 500;
public int maxHeight = 500;
public String[] whiteList = new String[]{};
public boolean isCheckPixels = true; //是否检查大像素图片
public int maxWidth = 1000;
public int maxHeight = 1000;
public String[] whiteList = new String[]{}; //优化图片白名单
public String mctoolsDir = "";
public boolean isSupportAlphaWebp = false; //是否支持webp化透明通道的图片,如果开启,请确保minSDK >= 18,或做了其他兼容措施
public boolean multiThread = true;
public String[] bigImageWhiteList = new String[]{}; //大图检测白名单

public void maxSize(float maxSize) {
this.maxSize = maxSize;
}

public void isCheck(boolean check) {
isCheck = check;
}

public void isCompress(boolean compress) {
isCompress = compress;
public void isCheckSize(boolean check) {
isCheckSize = check;
}

public void isWebpConvert(boolean webpConvert) {
isWebpConvert = webpConvert;
public void optimizeType(String optimizeType) {
this.optimizeType = optimizeType;
}

public void isJPGConvert(boolean JPGConvert) {
isJPGConvert = JPGConvert;
public void isSupportAlphaWebp(boolean isSupportAlphaWebp) {
this.isSupportAlphaWebp = isSupportAlphaWebp;
}

public void enableWhenDebug(boolean enableWhenDebug) {
this.enableWhenDebug = enableWhenDebug;
}

public void isCheckSize(boolean checkSize) {
isCheckSize = checkSize;
public void isCheckPixels(boolean checkSize) {
isCheckPixels = checkSize;
}

public void maxWidth(int maxWidth) {
Expand All @@ -59,11 +58,39 @@ public void mctoolsDir(String mctoolsDir) {
this.mctoolsDir = mctoolsDir;
}

public boolean isMultiThread() {
return multiThread;
public void maxStroageSize(float maxSize) {
this.maxSize = maxSize;
}

public void setMultiThread(boolean multiThread) {
public void multiThread(boolean multiThread) {
this.multiThread = multiThread;
}

public void bigImageWhiteList(String[] bigImageWhiteList) {
this.bigImageWhiteList = bigImageWhiteList;
}

public String toString() {
StringBuilder result = new StringBuilder();
result.append("<<<<<<<<<<<<<<McConfig>>>>>>>>>>>>" + "\n");
result.append("maxSize :" + maxSize + "\n"
+ "isCheckSize: " + isCheckSize + "\n"
+ "optimizeType: " + optimizeType + "\n"
+ "enableWhenDebug: " + enableWhenDebug + "\n"
+ "isCheckPixels: " + isCheckPixels + "\n"
+ "maxWidth: " + maxWidth + ", maxHeight: " + maxHeight + "\n"
+ "mctoolsDir: " + mctoolsDir + "\n"
+ "isSupportAlphaWebp: " + isSupportAlphaWebp + "\n"
+ "multiThread: " + multiThread + "\n"
+ "whiteList : \n");
for(String file : whiteList) {
result.append(" -> : " + file + "\n");
}
result.append("bigImageWhiteList: \n");
for(String file: bigImageWhiteList) {
result.append(" -> : " + file + "\n");
}
result.append("<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>");
return result.toString();
}
}
Loading

0 comments on commit db77743

Please sign in to comment.