Giter Club home page Giter Club logo

img-optimizer-gradle-plugin's Introduction

maven License Android Arsenal GitHub stars

中文版

img-optimizer-gradle-plugin

A gradle plugin for optimizing PNGs, effectively reducing APK size. Both extreme compression and lossless compression are available.

Available OS

Tested on macOSwindows10Ubuntu16.04LTS(amd64). If you have any questions, plz open issues.

How to use

Add the following Gradle configuration to your build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        ...
        classpath 'com.chenenyu:img-optimizer:latestVersion'
    }
}

Then in your moudle's build.gradle:

apply plugin: 'img-optimizer'

Now you can see the tasks in task tree:
Task
Double click to execute the task.

Configuration

You can add the following options to custom the task:

optimizerOptions {
    triggerSize 5
    type "lossy"
    suffix "_opt"
}
  1. triggerSize Used for filtering pictures. Picture whose size is less than this option will be ignored. Defaults to 0.
  2. type Now supports"lossy" and "lossless""lossy" means extreme compression(recommend, default, fast, effective),"lossless" means loseless compression(slow, inefficient)。
  3. suffix The suffix of the picture which has been optimized. If "_opt",the optimizer will generate a new picture orignal_opt.png for original.png. Defaults to null.

Preview

Original png Extreme compression(lossy) Loseless compression(lossless)
526K 195K(reduce 63%) 473K(reduce 10%)
原图 极限压缩 无损压缩

Note

If there are multiple modules in your project, please add the optimizer in where you want to execute optimization since each module is independent. The optimizer will generate log file in the root directory of current module.

License

Apache 2.0

img-optimizer-gradle-plugin's People

Contributors

chenenyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

img-optimizer-gradle-plugin's Issues

引入配置失败

报错是

Gradle *** project refresh failed
Error:Cause: com/android/build/gradle/internal/model/DefaultAndroidProject:Unsupported major.minor version 52.0

English

Please update your repository for English language

日志显示error

2016-07-11 09:20:52 error: Failed! /(项目地址)/app/src/main/res/mipmap-xhdpi/play_ptz_disabel.png

2016-07-11 09:20:52 error: Exit: 2. /(项目地址)/app/build/pngquant/pngquant: 1: /(项目地址)/app/build/pngquant/pngquant: ����������H: not found/(项目地址)/app/build/pngquant/pngquant: 2: /(项目地址)/app/build/pngquant/pngquant: Syntax error: "(" unexpec

triggerSize 怎么用

你好triggerSize的数值如何计算,怎么来的,建议设成多少,多谢

会不会进行无限压缩?

比如我上个版本执行了一次优化,这个版本再在执行一次,会不会还对上个版本已经优化过的图片再进行压缩?

img-optimizer在gradle 6.1.1版本里报错

我把android studio更新到了4.0,而gradle最低版本要求为6.1.1,在sync build.gradle时报错,提示
Gradle sync failed: Unnecessarily replacing a task that does not exist is not supported. Use create() or register() directly instead. You attempted to replace a task named 'optimizeAppDebug', but there is no existing task with that name
当我注释掉apply plugin: 'img-optimizer'后,项目能够正常编译。

'imgDirs' is missing

Some problems were found with the configuration of task ':app:optimizeRelease' (type 'ImgOptimizerTask').

  • Type 'com.chenenyu.imgoptimizer.task.ImgOptimizerTask' property 'imgDirs' is missing an input or output annotation.

gradle:7.0.4

img_opttimezer.log

6-07-14 14:13:17 info: 230 images need to be optimized.
2016-07-14 14:13:28 info: Total: 230, Succeed: 1, Skipped: 229, Failed: 0, Saved: 0.001953125KB
2016-07-14 14:13:19 info: Succeed! 2940B-->2938B, 0.06802721% saved!
2016-07-14 14:13:28 info: Task optimizeAppDebug executed successfully.
Why to skip so much?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.