一款Android端自动化图片压缩的gradle插件,一键扫描项目中的资源目录并进行批量图片压缩,提供3种压缩方式,支持有损及无损压缩.同时会记录已压缩的文件,适合个人及团队协同使用.
An Android gradle plugin that scans the resource directory in the project and performs batch image compression. It provides 3 compression methods to support lossy and lossless compression. It also records compressed files, which is suitable for personal and team collaboration.
Step 1: in the project
's build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
...
classpath 'io.github.duking666:ImgCompressPlugin:1.2.1'
}
}
...
...
//Image compressor configuration
apply plugin: 'img-compressor'
imgCompressOpt{
way="pngquant"
test = false
whiteFiles=["text_pic1.png","test_pic2.jpg"]
minSize=5
tinyKeys=["your key"]
}
Step 2: After the introduction, click sync now
. After the gradle configuration is completed, the following figure imgCompressTask
will be displayed. Double-click it to execute, wait for the compression result.
way
:Set the compression method, support 3 common compressions,include "tinypng", "pngquant", "zopflip" ,3 select 1, compression method selection and compression effect see the following figuretest
:Set whether the test mode is on, false
means that the compressed image directly overwrites the original image, and true
means that the original image and the compressed image are output to the test directory(Project/ImageCompressTest).whiteFiles
:Optional, whitelisted file array, which will no compressionminSize
:The unit is KB,the original image is larger than a certain value to trigger compression, and 0 means all compression.tinyKeys
:Optional, only needed in the case of way="tinypng"origin pic | tinypng | pngquant | zopflip |
---|---|---|---|
Compression type | Lossy | Lossy | Lossless |
1.3M | 445KB | 542KB | 903KB |
test=true
in the configuration, the original image and the compressed image are output to the test directory (Project/ImageCompressTest)
, and the compressed image is named xxxx(test).png
Introduce the plugin, configure the test mode test=false, after executing the imgCompressTask
for the first time, check the log and print a similar log:
After executing the task, the image-compressed-info.json
file will be generated in the project directory, and the compressed image information will be recorded.
Through Android Studio's own version control to compare whether the image before and after compression is distorted, add distortion pictures (usually rarely) to the white list, and revert to restore the original image
Add image-compressed-info.json
file to version control, submit modified image and json file
In the subsequent version development, anyone on the team will add any images during the development process, or after the version is tested, a task can be executed to compress the images imported by the new version. The old version of the image remains unchanged. also will not be recompress by other team members.
Tested on macOS, windows10