Code Monkey home page Code Monkey logo

svg-stockpile's Introduction

svg-stockpile

Build Status

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 500

Building

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

License

This project is available under the terms of the ISC license. See the LICENSE file for the copyright information and licensing terms.

svg-stockpile's People

Contributors

michaelbull avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

svg-stockpile's Issues

Require viewBox in Svg4j constructor

As it is always required it would be better suited being provided to the constructor instead of having preconditions check to see if it has been manually set.

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.