From 100f41d2c5979cab8f627c3661f887d4a0a8c17a Mon Sep 17 00:00:00 2001 From: CyanStone Date: Tue, 4 Jun 2019 14:44:43 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=BD=AC=E5=8C=96webp?= =?UTF-8?q?=E5=92=8C=E5=8E=8B=E7=BC=A9=E5=9B=BE=E7=89=87=E4=B8=A4=E7=A7=8D?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/smallsoho/mcplugin/image/Config.java | 73 +++++++---- .../smallsoho/mcplugin/image/ImagePlugin.kt | 119 ++++++++++++------ .../mcplugin/image/utils/CompressUtil.kt | 35 ++++-- .../mcplugin/image/utils/ImageUtil.kt | 4 +- .../mcplugin/image/webp/WebpUtils.kt | 48 ++++--- 5 files changed, 182 insertions(+), 97 deletions(-) diff --git a/src/main/java/com/smallsoho/mcplugin/image/Config.java b/src/main/java/com/smallsoho/mcplugin/image/Config.java index 6a3d842..f076671 100644 --- a/src/main/java/com/smallsoho/mcplugin/image/Config.java +++ b/src/main/java/com/smallsoho/mcplugin/image/Config.java @@ -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 = true; //是否支持webp化透明通道的图片 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) { @@ -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("<<<<<<<<<<<<<>>>>>>>>>>>" + "\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(); + } } diff --git a/src/main/java/com/smallsoho/mcplugin/image/ImagePlugin.kt b/src/main/java/com/smallsoho/mcplugin/image/ImagePlugin.kt index 93df98c..0581257 100644 --- a/src/main/java/com/smallsoho/mcplugin/image/ImagePlugin.kt +++ b/src/main/java/com/smallsoho/mcplugin/image/ImagePlugin.kt @@ -17,7 +17,9 @@ class ImagePlugin : Plugin { private lateinit var mcImageProject: Project private lateinit var mcImageConfig: Config - + private var oldSize: Long = 0 + private var newSize: Long = 0 + val bigImgList = ArrayList() override fun apply(project: Project) { mcImageProject = project @@ -60,15 +62,7 @@ class ImagePlugin : Plugin { variant as BaseVariantImpl - if (mcImageConfig.mctoolsDir.isBlank()) { - FileUtil.setRootDir(project.rootDir.path) - } else { - FileUtil.setRootDir(mcImageConfig.mctoolsDir) - } - - if (!FileUtil.getToolsDir().exists()) { - throw GradleException("You need put the mctools dir in project root") - } + checkMcTools(project) //debug enable if (isDebugTask && !mcImageConfig.enableWhenDebug) { @@ -81,18 +75,17 @@ class ImagePlugin : Plugin { mcPicTask.doLast { _ -> println("---- McImage Plugin Start ----") + println(mcImageConfig.toString()) val dir = variant.mergeResources.computeResourceSetList0() //强行调用一下 - val bigImgList = ArrayList() - val cacheList = ArrayList() val imageFileList = ArrayList() if (dir != null) { for (channelDir: File in dir) { - listDir(channelDir, imageFileList, cacheList, object : IBigImage { + traverseResDir(channelDir, imageFileList, cacheList, object : IBigImage { override fun onBigImage(file: File) { bigImgList.add(file.absolutePath) } @@ -100,19 +93,12 @@ class ImagePlugin : Plugin { } } - if (bigImgList.size != 0) { - val stringBuffer = StringBuffer("You have big Img!!!! \n") - for (i: Int in 0 until bigImgList.size) { - stringBuffer.append(bigImgList[i]) - stringBuffer.append("\n") - } - throw GradleException(stringBuffer.toString()) - } + checkBigImage() val start = System.currentTimeMillis() - mtCompress(imageFileList) - + mtDispathOptimizeTask(imageFileList) + println(sizeInfo()) println("---- McImage Plugin End ----, Total Time(ms) : ${System.currentTimeMillis() - start}") } @@ -134,7 +120,7 @@ class ImagePlugin : Plugin { } } - private fun listDir(file: File, imageFileList: ArrayList, cacheList: ArrayList, iBigImage: IBigImage) { + private fun traverseResDir(file: File, imageFileList: ArrayList, cacheList: ArrayList, iBigImage: IBigImage) { if (cacheList.contains(file.absolutePath)) { return } else { @@ -143,7 +129,7 @@ class ImagePlugin : Plugin { if (file.isDirectory) { file.listFiles().forEach { if (it.isDirectory) { - listDir(it, imageFileList, cacheList, iBigImage) + traverseResDir(it, imageFileList, cacheList, iBigImage) } else { filterImage(it, imageFileList, iBigImage) } @@ -157,22 +143,23 @@ class ImagePlugin : Plugin { if (mcImageConfig.whiteList.contains(file.name) || !ImageUtil.isImage(file)) { return } - if ((mcImageConfig.isCheck && ImageUtil.isBigImage(file, mcImageConfig.maxSize)) - || (mcImageConfig.isCheckSize - && ImageUtil.isBigSizeImage(file, mcImageConfig.maxWidth, mcImageConfig.maxHeight))) { + if (((mcImageConfig.isCheckSize && ImageUtil.isBigSizeImage(file, mcImageConfig.maxSize)) + || (mcImageConfig.isCheckPixels + && ImageUtil.isBigPixelImage(file, mcImageConfig.maxWidth, mcImageConfig.maxHeight))) + && !mcImageConfig.bigImageWhiteList.contains(file.name)) { iBigImage.onBigImage(file) } imageFileList.add(file) } - private fun mtCompress(imageFileList: ArrayList) { - if (imageFileList == null || imageFileList.size == 0) { + private fun mtDispathOptimizeTask(imageFileList: ArrayList) { + if (imageFileList == null || imageFileList.size == 0 || !bigImgList.isEmpty()) { return } val coreNum = Runtime.getRuntime().availableProcessors() - if (imageFileList.size < coreNum || !mcImageConfig.isMultiThread) { + if (imageFileList.size < coreNum || !mcImageConfig.multiThread) { for (file in imageFileList) { - rawCompress(file) + optimizeImage(file) } } else { val results = ArrayList>() @@ -183,7 +170,7 @@ class ImagePlugin : Plugin { val to = if (i == coreNum - 1) imageFileList.size - 1 else (i + 1) * part - 1 results.add(pool.submit(Callable { for (index in from..to) { - rawCompress(imageFileList[index]) + optimizeImage(imageFileList[index]) } })) } @@ -196,12 +183,68 @@ class ImagePlugin : Plugin { } } - private fun rawCompress(file: File) { - if (mcImageConfig.isCompress) { - CompressUtil.compressImg(file) + private fun optimizeImage(file: File) { + var path: String = file.path + if(File(path).exists()) { + oldSize += File(path).length() } - if (mcImageConfig.isWebpConvert) { - WebpUtils.securityFormatWebp(file, mcImageConfig, mcImageProject) + when (mcImageConfig.optimizeType) { + Config.OPTIMIZE_WEBP_CONVERT -> + WebpUtils.securityFormatWebp(file, mcImageConfig, mcImageProject) + Config.OPTIMIZE_COMPRESS_PICTURE -> + CompressUtil.compressImg(file) } + countNewSize(path) + } + + private fun countNewSize(path: String) { + if(File(path).exists()) { + newSize += File(path).length() + } else { + //转成了webp + val indexOfDot = path.lastIndexOf(".") + val webpPath = path.substring(0, indexOfDot) + ".webp" + if(File(webpPath).exists()) { + newSize += File(webpPath).length() + } else { + LogUtil.log("McImage: optimizeImage have some Exception!!!") + } + } + } + + private fun checkBigImage() { + if (bigImgList.size != 0) { + val stringBuffer = StringBuffer("You have big Imgages with big size or large pixels," + + "please confirm whether they are necessary or whether they can to be compressed. " + + "If so, you can config them into bigImageWhiteList to fix this Exception!!!\n") + for (i: Int in 0 until bigImgList.size) { + stringBuffer.append(bigImgList[i]) + stringBuffer.append("\n") + } + throw GradleException(stringBuffer.toString()) + } + } + + + private fun checkMcTools(project: Project) { + if (mcImageConfig.mctoolsDir.isBlank()) { + FileUtil.setRootDir(project.rootDir.path) + } else { + FileUtil.setRootDir(mcImageConfig.mctoolsDir) + } + + if (!FileUtil.getToolsDir().exists()) { + throw GradleException("You need put the mctools dir in project root") + } + } + + private fun sizeInfo(): String { + return "->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" + + "before McImage optimize: " + oldSize / 1024 + "KB\n" + + "after McImage optimize: " + newSize / 1024 + "KB\n" + + "McImage optimize size: " + (oldSize - newSize) / 1024 + "KB\n" + + "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<-" + + } } \ No newline at end of file diff --git a/src/main/java/com/smallsoho/mcplugin/image/utils/CompressUtil.kt b/src/main/java/com/smallsoho/mcplugin/image/utils/CompressUtil.kt index 6a45e35..a3a03ee 100644 --- a/src/main/java/com/smallsoho/mcplugin/image/utils/CompressUtil.kt +++ b/src/main/java/com/smallsoho/mcplugin/image/utils/CompressUtil.kt @@ -7,16 +7,37 @@ class CompressUtil { companion object { private const val TAG = "Compress" fun compressImg(imgFile: File) { - if (ImageUtil.isImage(imgFile)) { - val oldSize = imgFile.length() - if (ImageUtil.isJPG(imgFile)) { - Tools.cmd("guetzli", "${imgFile.path} ${imgFile.path}") + if (!ImageUtil.isImage(imgFile)) { + return + } + + val oldSize = imgFile.length() + var newSize = 0L + if (ImageUtil.isJPG(imgFile)) { + var tempFilePath: String = "${imgFile.path.substring(0, imgFile.path.lastIndexOf("."))}_temp" + + "${imgFile.path.substring(imgFile.path.lastIndexOf("."))}" + Tools.cmd("guetzli", "${imgFile.path} ${tempFilePath}") + val tempFile: File = File(tempFilePath) + newSize = tempFile.length() + println("newSize = ${newSize}") + if (newSize < oldSize) { + var imgFileName: String = imgFile.path + if (imgFile.exists()) { + imgFile.delete() + } + tempFile.renameTo(File(imgFileName)) } else { - Tools.cmd("pngquant", "--skip-if-larger --speed 3 --force --output ${imgFile.path} -- ${imgFile.path}") + if (tempFile.exists()) { + tempFile.delete() + } } - val newSize = imgFile.length() - LogUtil.log(TAG, imgFile.path, oldSize.toString(), newSize.toString()) + + } else { + Tools.cmd("pngquant", "--skip-if-larger --speed 1 --nofs --strip --force --output ${imgFile.path} -- ${imgFile.path}") + newSize = File(imgFile.path).length() } + + LogUtil.log(TAG, imgFile.path, oldSize.toString(), newSize.toString()) } } diff --git a/src/main/java/com/smallsoho/mcplugin/image/utils/ImageUtil.kt b/src/main/java/com/smallsoho/mcplugin/image/utils/ImageUtil.kt index 2faf535..66eba80 100644 --- a/src/main/java/com/smallsoho/mcplugin/image/utils/ImageUtil.kt +++ b/src/main/java/com/smallsoho/mcplugin/image/utils/ImageUtil.kt @@ -38,7 +38,7 @@ class ImageUtil { } } - fun isBigImage(imgFile: File, maxSize: Float): Boolean { + fun isBigSizeImage(imgFile: File, maxSize: Float): Boolean { if (isImage(imgFile)) { if (imgFile.length() >= maxSize) { LogUtil.log(SIZE_TAG, imgFile.path, true.toString()) @@ -48,7 +48,7 @@ class ImageUtil { return false } - fun isBigSizeImage(imgFile: File, maxWidth: Int, maxHeight: Int): Boolean { + fun isBigPixelImage(imgFile: File, maxWidth: Int, maxHeight: Int): Boolean { if (isImage(imgFile)) { val sourceImg = ImageIO.read(FileInputStream(imgFile)) if (sourceImg.height > maxHeight || sourceImg.width > maxWidth) { diff --git a/src/main/java/com/smallsoho/mcplugin/image/webp/WebpUtils.kt b/src/main/java/com/smallsoho/mcplugin/image/webp/WebpUtils.kt index 9dd4e78..7d189f1 100644 --- a/src/main/java/com/smallsoho/mcplugin/image/webp/WebpUtils.kt +++ b/src/main/java/com/smallsoho/mcplugin/image/webp/WebpUtils.kt @@ -2,32 +2,25 @@ package com.smallsoho.mcplugin.image.webp import com.smallsoho.mcplugin.image.Const import com.smallsoho.mcplugin.image.Config -import com.smallsoho.mcplugin.image.utils.AndroidUtil -import com.smallsoho.mcplugin.image.utils.ImageUtil -import com.smallsoho.mcplugin.image.utils.LogUtil -import com.smallsoho.mcplugin.image.utils.Tools +import com.smallsoho.mcplugin.image.utils.* import org.gradle.api.Project import java.io.File class WebpUtils { companion object { - private const val VERSION_SUPPORT_WEBP = 14 - private const val VERSION_SUPPORT_TRANSPARENT_WEBP = 18 + private const val VERSION_SUPPORT_WEBP = 14 //api>=14设设备支持webp + private const val VERSION_SUPPORT_TRANSPARENT_WEBP = 18 //api>=18支持透明通道 private const val TAG = "Webp" private fun isPNGConvertSupported(project: Project): Boolean { return AndroidUtil.getMinSdkVersion(project) >= VERSION_SUPPORT_WEBP } - private fun isTransparentPNGSupported(project: Project): Boolean { - return AndroidUtil.getMinSdkVersion(project) >= VERSION_SUPPORT_TRANSPARENT_WEBP - } - private fun formatWebp(imgFile: File) { if (ImageUtil.isImage(imgFile)) { val webpFile = File("${imgFile.path.substring(0, imgFile.path.lastIndexOf("."))}.webp") - Tools.cmd("cwebp", "${imgFile.path} -o ${webpFile.path} -quiet") + Tools.cmd("cwebp", "${imgFile.path} -o ${webpFile.path} -m 6 -quiet") if (webpFile.length() < imgFile.length()) { LogUtil.log(TAG, imgFile.path, imgFile.length().toString(), webpFile.length().toString()) if (imgFile.exists()) { @@ -38,31 +31,32 @@ class WebpUtils { if (webpFile.exists()) { webpFile.delete() } + LogUtil.log("[${TAG}][${imgFile.name}] do not convert webp because the size become larger!") } } } fun securityFormatWebp(imgFile: File, config: Config, project: Project) { + if(!isPNGConvertSupported(project)) { + throw Exception("minSDK < 14, Webp is not Support! Please choose other optimize Type!") + } if (ImageUtil.isImage(imgFile)) { - //png - if (imgFile.name.endsWith(Const.PNG)) { - if (isPNGConvertSupported(project)) { - if (ImageUtil.isAlphaPNG(imgFile)) { - if (isTransparentPNGSupported(project)) { - formatWebp(imgFile) - } - } else { + if(config.isSupportAlphaWebp) { + formatWebp(imgFile) + } else { + if(imgFile.name.endsWith(Const.JPG) || imgFile.name.endsWith(Const.JPEG)) { + //jpg + formatWebp(imgFile) + } else if(imgFile.name.endsWith(Const.PNG) ){ + //png + if(!ImageUtil.isAlphaPNG(imgFile)) { + //不包含透明通道 formatWebp(imgFile) + } else { + //包含透明通道的png,进行压缩 + CompressUtil.compressImg(imgFile) } } - //jpg - } else if (imgFile.name.endsWith(Const.JPG) || imgFile.name.endsWith(Const.JPEG)) { - if (config.isJPGConvert) { - formatWebp(imgFile) - } - //other - } else { - LogUtil.log(TAG, imgFile.path, "don't convert") } } From d9cbc4b5bb38ff4b86701de7c2a06e88bc48420b Mon Sep 17 00:00:00 2001 From: CyanStone Date: Tue, 4 Jun 2019 15:30:05 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=EF=BC=8C=E4=BF=AE=E6=94=B9ReadMe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-CN.md | 32 ++++++++++++++++++-------------- README.md | 32 ++++++++++++++++++-------------- bintray.gradle | 2 +- publish.gradle | 2 +- 4 files changed, 38 insertions(+), 30 deletions(-) diff --git a/README-CN.md b/README-CN.md index 6d9ec12..8b8c093 100644 --- a/README-CN.md +++ b/README-CN.md @@ -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 @@ -59,7 +60,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.smallsoho.mobcase:McImage:1.0.1' + classpath 'com.smallsoho.mobcase:McImage:1.4.0' } } ``` @@ -82,18 +83,21 @@ 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 true //是否支持带有透明度的webp,default true + multiThread true //是否开启多线程处理图片,default true + bigImageWhiteList = [ //默认为空,如果添加,大图检测将跳过这些图片 + ] } ``` diff --git a/README.md b/README.md index 1afa721..c80cd6b 100644 --- a/README.md +++ b/README.md @@ -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. @@ -59,7 +60,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.smallsoho.mobcase:McImage:1.0.1' + classpath 'com.smallsoho.mobcase:McImage:1.4.0' } } ``` @@ -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 true //Whether support convert the Image with Alpha chanel to Webp,default true, its need api level >=18 or do some compatible measures + multiThread true //是否开启多线程处理图片,default true + bigImageWhiteList = [ //默认为空,如果添加,大图检测将跳过这些图片 + ] } ``` diff --git a/bintray.gradle b/bintray.gradle index 623fb3c..2df0d55 100644 --- a/bintray.gradle +++ b/bintray.gradle @@ -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()) diff --git a/publish.gradle b/publish.gradle index 82cd6a6..7342cbb 100644 --- a/publish.gradle +++ b/publish.gradle @@ -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' From bc47496feac2b2e956bc52af0b5a5122276bab34 Mon Sep 17 00:00:00 2001 From: CyanStone Date: Tue, 4 Jun 2019 16:02:05 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=80=8F=E6=98=8E?= =?UTF-8?q?=E5=BA=A6Webp=E5=BC=80=E5=85=B3=E9=BB=98=E8=AE=A4=E5=85=B3?= =?UTF-8?q?=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++++---- src/main/java/com/smallsoho/mcplugin/image/Config.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c80cd6b..80933c6 100644 --- a/README.md +++ b/README.md @@ -91,13 +91,13 @@ McImageConfig { 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 + whiteList = [ //do not do any optimization for the images who in the list "icon_launcher.png" ] mctoolsDir "$rootDir/tools" - isSupportAlphaWebp true //Whether support convert the Image with Alpha chanel to Webp,default true, its need api level >=18 or do some compatible measures - multiThread true //是否开启多线程处理图片,default true - bigImageWhiteList = [ //默认为空,如果添加,大图检测将跳过这些图片 + isSupportAlphaWebp false //Whether support convert the Image with Alpha chanel to Webp,default false, 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 ] } ``` diff --git a/src/main/java/com/smallsoho/mcplugin/image/Config.java b/src/main/java/com/smallsoho/mcplugin/image/Config.java index f076671..64b6d60 100644 --- a/src/main/java/com/smallsoho/mcplugin/image/Config.java +++ b/src/main/java/com/smallsoho/mcplugin/image/Config.java @@ -14,7 +14,7 @@ public class Config { public int maxHeight = 1000; public String[] whiteList = new String[]{}; //优化图片白名单 public String mctoolsDir = ""; - public boolean isSupportAlphaWebp = true; //是否支持webp化透明通道的图片 + public boolean isSupportAlphaWebp = false; //是否支持webp化透明通道的图片,如果开启,请确保minSDK >= 18,或做了其他兼容措施 public boolean multiThread = true; public String[] bigImageWhiteList = new String[]{}; //大图检测白名单 From 767508b92c7308303dace7fa6ab8687e7d3a6012 Mon Sep 17 00:00:00 2001 From: CyanStone Date: Tue, 4 Jun 2019 16:20:15 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9read=20me?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-CN.md | 28 ++++++++++++++-------------- README.md | 28 ++++++++++++++-------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/README-CN.md b/README-CN.md index 8b8c093..793067a 100644 --- a/README-CN.md +++ b/README-CN.md @@ -84,20 +84,20 @@ mctools ```groovy McImageConfig { 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 true //是否支持带有透明度的webp,default true - multiThread true //是否开启多线程处理图片,default true - bigImageWhiteList = [ //默认为空,如果添加,大图检测将跳过这些图片 - ] + 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 = [ //默认为空,如果添加,大图检测将跳过这些图片 + ] } ``` diff --git a/README.md b/README.md index 80933c6..3b60a07 100644 --- a/README.md +++ b/README.md @@ -85,20 +85,20 @@ You can set the config in build.gradle.If you not set this,all config will use d ```groovy McImageConfig { 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, 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 - ] + 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 + ] } ```