Skip to content

Latest commit

 

History

History
69 lines (52 loc) · 3.01 KB

README.zh-cn.md

File metadata and controls

69 lines (52 loc) · 3.01 KB

其它语言版本: English,简体中文.

Build Status Download

TinyPngPlugin

TinyPngPlugin是一个TinyPng的Gradle插件,它能够批量地压缩你项目中的图片

获得Tiny的API Key

在使用该插件前, 你需要先获得一个Tiny的API Key。 首先跳转到Tiny Developers Page,然后输入你的姓名和邮箱来获得这个Key

注意: 一个Key每个月可以免费压缩500张图片,超过500张后就需要付费后才能继续使用

使用教程

首先在根目录中的build.gradle文件中添加TinyPngPlugin的依赖:

dependencies {
	classpath 'com.waynell.tinypng:TinyPngPlugin:1.0.5'
}

然后在app目录中的build.gradle文件中应用该插件,并配置tinyinfo

apply plugin: 'com.waynell.tinypng'

tinyInfo {
	resourceDir = [
		// 你的资源目录
        "app/src/main/res",
        "lib/src/main/res"
	]
    resourcePattern = [
    	// 你的资源文件夹
    	"drawable[a-z-]*",
        "mipmap[a-z-]*"
    ]
    whiteList = [
    	// 在这里添加文件白名单,支持正则表达式
    ]
    apiKey = 'your tiny API key'
}

使用Android Studio的同学,可以在tinypng目录中找到相关的构建任务。或者也可以直接在终端中运行./gradlew tinyPng命令来执行任务

TinyPngPlugin会将压缩结果保存到compressed-resource.json这个文件中,下次再运行任务时会自动跳过那些已经被压缩过的文件

致谢

TinyPIC_Gradle_Plugin

Licence

MIT License

Copyright (c) 2016 Wayne Yang

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.