GithubHelp home page GithubHelp logo

spritey's Introduction

Spritey

GitHub license Twitter

While sprites may not be in vogue anymore and font svg based icon libraries are all the rage, css based sprites still have their place (i think), so why not implement yet another sprite generator in .NET Core.

Spritey is a sprite generator. It takes a directory of images and converts them to an optimally packed rectangle, outputting a css embedded or referenced gif or png as well as the accompanying css stylesheet.

While the generated gif is substantially smaller than the png, it suffers from quality degradation, especially if the source images vary in style (colors / complexity). The output should always be checked for quality.

Goal

The end goal of this project is to produce both a .NET Core NuGet library for consuming apps, as well as a .NET Core Global Tool for CLI sprite generation.

Build Status

Build Status Code Coverage Quality
Windows & Linux Build Status codecov sonarcloud

Example:

Input

image1 image2 image3 image4 image5 image6 image7

Output

image1

.img-sprite{background: transparent url(sprite.png);}
i.img-sprite{display:inline-block;}
.img-sprite.img-icons8-padlock-100{height:100px;width:100px;background-position: -0px -0px;}
.img-sprite.img-icons8-lion-statue-48{height:48px;width:48px;background-position: -0px -100px;}
.img-sprite.img-icons8-news-48{height:48px;width:48px;background-position: -48px -100px;}
.img-sprite.img-icons8-public-transportation-48{height:48px;width:48px;background-position: -0px -148px;}
.img-sprite.img-icons8-roundabout-48{height:48px;width:48px;background-position: -48px -148px;}
.img-sprite.img-icons8-workstation-40{height:40px;width:40px;background-position: -0px -196px;}
.img-sprite.img-icons8-public-30{height:30px;width:30px;background-position: -40px -196px;}

API

Option 1

  • generate css with gif or png that is embedded or referenced
using Spritey;

string directoryOfImages = ""; // path to your images
string outputDirectory = ""; // path to output files

using (Sprite sprite = new Sprite(directoryOfImages))
{
    // css with referenced gif
    sprite.Save("spriteName", outputDirectory, false, SpriteFormat.Gif);
}

Option 2

  • generate css with embedded or referenced gif
  • and generate css with embedded or referenced png
using Spritey;

string directoryOfImages = ""; // path to your images
string outputDirectory = ""; // path to output files

using (Sprite sprite = new Sprite(directoryOfImages))
{
    // css with embedded gif and css with embedded png
    sprite.Save("spriteName", outputDirectory, true);
}

Option 3

  • generate css with embedded gif
  • and generate css with embedded png
  • and generate css and referenced gif
  • and generate css and referenced png
using Spritey;

string directoryOfImages = ""; // path to your images
string outputDirectory = ""; // path to output files

using (Sprite sprite = new Sprite(directoryOfImages))
{
    // output all variations
    sprite.Save("spriteName", outputDirectory);
}

Getting started

Building in VSCode

  • Build: ctrl + p => task build
  • Test: ctrl + p => task test

spritey's People

Contributors

azure-pipelines[bot] avatar brandonboone avatar

Watchers

 avatar

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.