Giter Club home page Giter Club logo

image-to-gradient's Introduction

image-to-gradient

Downloads pe Month Total Downloads Build Status Coverage Status

This project allows you to easily create CSS gradients from images. The step count is variable. Any angle is supported. Alpha channel is also processed.

This is my first NPM module ever.

alt tag

Usage

There is one exported function with 3 parameters. You specify the path through the first parameter, you pass in the options in the second parameter and you pass in a callback function in the third parameter;

The example below creates a gradient from an image and generates a dummy html file with the background set to the gradient.

var imageToGradient = require('image-to-gradient');

var options = {
    angle:10, // gradient angle in degrees
    steps:64  // number of steps
}

imageToGradient('testimage.jpg', options, function(err, cssGradient){
    if (err) throw err;
    var html = `
    <html>
        <head>
            <style>
                html{
                    width:100%;
                    height:100%;
                    background:${cssGradient};
                }
            </style>    
        </head>
        <body>
        </body>
    </html>`
    var fs = require('fs'); 
    fs.writeFile('output.html',html);
});

What can I use it for?

  • Need a background? Create a gradient from an image.
  • Optimise site loading speed by initially replacing images with gradients.
  • Make art! The gradients are beautiful.
  • Need a palette? Create a gradient form an image, use it as a palette.

image-to-gradient's People

Contributors

mollwe avatar peterekepeter avatar

Watchers

 avatar  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.