https://github.com/diffplug/image-grinder
ImageGrinder: Image manipulation for Gradle
https://github.com/diffplug/image-grinder
Last synced: 5 months ago
JSON representation
ImageGrinder: Image manipulation for Gradle
- Host: GitHub
- URL: https://github.com/diffplug/image-grinder
- Owner: diffplug
- License: apache-2.0
- Created: 2017-09-19T14:57:51.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2021-12-16T22:31:38.000Z (about 4 years ago)
- Last Synced: 2025-03-11T06:49:43.429Z (10 months ago)
- Language: Java
- Homepage:
- Size: 817 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
#
ImageGrinder:
image manipulation for Gradle
[](https://plugins.gradle.org/plugin/com.diffplug.image-grinder)
[](https://search.maven.org/artifact/com.diffplug.gradle/image-grinder)
[](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0))
[](CHANGES.md)
[](https://javadoc.io/doc/com.diffplug.gradle/image-grinder/2.2.2/index.html)
[](https://gitter.im/diffplug/image-grinder)
[](https://circleci.com/gh/diffplug/image-grinder)
## Simple image processing
To use it, just [add image-grinder to your buildscript](https://plugins.gradle.org/plugin/com.diffplug.image-grinder), and configure it as so:
```groovy
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`](https://javadoc.io/doc/com.diffplug.gradle/image-grinder/2.2.2/com/diffplug/gradle/imagegrinder/Img.html). Call its methods to grind it into whatever you need in the `dstDir`.
ImageGrinder uses the gradle [Worker API](https://docs.gradle.org/6.6/userguide/custom_tasks.html#worker_api) to use all your CPU cores for grinding, the [buildcache](https://docs.gradle.org/6.6/userguide/build_cache.html) to minimize the necessary work, and it also supports the [configuration cache](https://docs.gradle.org/6.6/userguide/configuration_cache.html) for near-instant startup times. It does not currently support [incremental update](https://docs.gradle.org/6.0/userguide/custom_tasks.html#incremental_tasks), but if you go back to `2.1.3` you can get that back in return for losing the configuration cache (see [#9](https://github.com/diffplug/image-grinder/pull/9) for details).
## Configuration avoidance
The plugin creates tasks eagerly. If you wish to avoid this, you can rewrite the example above like this:
```gradle
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](CONTRIBUTING.md)!
## Acknowledgements
* [Tony McCrary](https://github.com/enleeten) and [l33t labs](http://www.l33tlabs.com/) for their [org.eclipse.ui.images.renderer](https://github.com/tomsontom/org.eclipse.ui-split/tree/0402ebd10a57f9c2ca5cd2da3479470f98f70973/bundles/org.eclipse.ui.images.renderer) maven plugin.
* Maintained by [DiffPlug](https://www.diffplug.com/).