svg-stockpile
Introduction
svg-stockpile
is an optimizing and stacking tool for Scalable Vector Graphics, written in Java.
With SVGs being heavily supported on the web many may wish to compress and package all of their SVG assets into a single optimized file. This technique is known as using a sprite-sheet, and can be achieved in SVG documents with the use of fragment identifiers, the use of which is fairly supported by most modern browsers.
Each fragment renders part of the SVG document by defining a view identifier. The unique views may then be rendered in an HTML document via the <img>
tag, such as in the following example:
<img src="example.svg#layer1" alt="Example" width="50" height="50" />
Documentation
Javadocs are available for both the API and the [Gradle Plugin] gradle-plugin-javadoc.
Installation
This project is available in the Maven Central Repository. The artifacts are signed with my personal GPG key.
API
To install the API in a Maven project, add the following dependency to your pom.xml
file:
<dependency>
<groupId>com.mikebull94.svg-stockpile</groupId>
<artifactId>api</artifactId>
<version>1.0.0</version>
</dependency>
To install the API in a Gradle project, add the following dependency to your build.gradle
file:
dependencies {
compile group: 'com.mikebull94.svg-stockpile', name: 'api', version: '1.0.0'
}
Gradle Plugin
To install the Gradle Plugin into your build lifecycle, add the following code to your build.gradle
file:
import com.mikebull94.stockpile.svg.SvgViewBox
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'com.mikebull94.svg-stockpile', name: 'gradle-plugin', version: '1.0.0'
}
}
apply plugin: 'com.mikebull94.svg-stockpile'
stockpile {
inputDir = projectDir
output = file('output.svg')
viewBox = new SvgViewBox(0, 0, 500, 500)
}
build.dependsOn stockpile
Example
An example class is included to show how typical API interaction is performed. It can be ran on a set of input SVGs such as the Wikimedia Community Logo variations distributed with this project, which are licensed for any purpose within the public domain.
The example requires the following program arguments:
inputDir
- The input directory of SVGs (e.g.api/src/main/resources
)output
- The output file (e.g.api/build/resources/main/output.svg
)minX
- The minimum x-coordinate of the viewBox.minY
- The minimum y-coordinate of the viewBox.width
- The width of the viewBox in pixels.height
- The height of the viewBox in pixels.
Correctly populated arguments should look similar to this:
api/src/main/resources api/build/resources/main/output.svg 0 0 500 500Building
Gradle is used as the project's build system. The [Gradle Wrapper] gradle-wrapper is included in the distribution, therefore you do not need to install Gradle on your system.
To build the program, run the tests, and generate Javadoc, run:
./gradlew
(on Unix-like platforms such as Linux and Mac OS X)gradlew
(on Windows using the gradlew.bat batch file)
FindBugs™ and PMD are used to lint the Java code and will fail the build on rule violations.
Testing
Tests are written in a behaviour-driven-development style and run using JUnit and Mockito.
Integration tests for the Gradle Plugin run using the Gradle TestKit.
Code coverage reports for the unit tests are generated by JaCoCo.
Dependencies
- Java 8 or above
- Google Guava
- SLF4J for logging
- JUnit for unit tests
- Mockito for unit tests
- APIviz for UML-like class diagrams in the generated Javadoc
- Gradle TestKit for integration tests
License
This project is available under the terms of the ISC license. See the LICENSE
file for the copyright information and licensing terms.