Skip to content

diffplug/image-grinder

Repository files navigation

ImageGrinder:
image manipulation for Gradle

Gradle plugin Maven central Apache 2.0

Changelog Javadoc Live chat CircleCI

Simple image processing

To use it, just add image-grinder to your buildscript, and configure it as so:

imageGrinder {
    // creates a task called 'processEclipseSvg', you can name it whatever you want
    // if the name starts with 'process', then the 'processResources' task will depend on it
    processEclipseSvg {
        srcDir = file('src')
        dstDir = file('dst')
        grinder { img ->
            img.render('.png')
            img.render('@2x.png', 2)
        }
        // used for up-to-date checking, bump this if the function above changes
        bumpThisNumberWhenTheGrinderChanges = 1
    }
}

Every single file in srcDir needs to be an image that ImageGrinder can parse. Each image will be parsed, and wrapped into an Img. Call its methods to grind it into whatever you need in the dstDir.

ImageGrinder uses the gradle Worker API to use all your CPU cores for grinding, the buildcache to minimize the necessary work, and it also supports the configuration cache for near-instant startup times. It does not currently support incremental update, but if you go back to 2.1.3 you can get that back in return for losing the configuration cache (see #9 for details).

Configuration avoidance

The plugin creates tasks eagerly. If you wish to avoid this, you can rewrite the example above like this:

def processEclipseSvg = tasks.register('processEclipseSvg', com.diffplug.gradle.imagegrinder.ImageGrinderTask) {
    srcDir = file('src')
    dstDir = file('dst')
    grinder { img ->
        img.render('.png')
        img.render('@2x.png', 2)
    }
    // used for up-to-date checking, bump this if the function above changes
    bumpThisNumberWhenTheGrinderChanges = 1
}
tasks.named(JavaPlugin.PROCESS_RESOURCES_TASK_NAME) {
  dependsOn processSvg
}

Limitations

  • ImageGrinder can only read SVG images.
  • ImageGrinder can only write PNG images.
  • ImageGrinder needs Gradle 6.0 or higher.

Not much of a grinder, but it does everything we needed. If you need more, we're happy to take PR's!

Acknowledgements

About

ImageGrinder: Image manipulation for Gradle

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages