You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

image-to-gradient

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-to-gradient

Convert an image to a linear CSS gradient of any angle.

2.0.2
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

image-to-gradient

Downloads pe Month Total Downloads Node CI Node.js Package Known Vulnerabilities

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.

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, (err) => {
            if (err) throw err;
            console.log('The file has been saved!');
        });
    });

What can I use it for?

Here is an example how to speed up initial load!

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

FAQs

Package last updated on 10 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts