Skip to main content

A python library to generate CSS gradient from an image. This is a fork of https://github.com/fraser-hemp/gradify. The original gradify project had only a CLI interface. With this fork, you can use gradify as a library in your Python code.

https://user-images.githubusercontent.com/2115303/35187613-c6fe6fe8-fe3b-11e7-9b9d-3e088e460a1d.jpg

Installation

Install the latest release from PyPI:

pip install gradify

Usage

gradify.generate_css(fp, single_color=False, use_color_spread=False)
  • fp: a filename (string), pathlib.Path object or a file object. The file object must implement read(), seek(), and tell() methods, and be opened in binary mode.

  • single_color: only produce a single, uniform background color - this is much quicker and has all browser support

  • use_color_spread: this flag will give the color which has the least spread over the image the highest priority when assigning directions (opposed to most dominant color). This feature improves overall accuracy, however adds complexity and in unique cases it produces counter-intuitive results

Example:

import gradify
css = gradify.generate_css('sample.png')

Advanced Usage

You can use Gradify class for advanced usage.

from gradify import Gradify

# simple usage
g = Gradify('sample.png', single_color=False, use_color_spread=False)
css = g.generate_css()

# advanced usage
g = Gradify('sample.png', single_color=False, use_color_spread=False, black_sensitivity=4.3,
            white_sensitivity=3, num_colors=4, resize=55, uniformness=7, use_prefixes=False)
css = g.generate_css()

Default parameters produce good result.

From original repo:

The only suggestion is increasing the uniformness (by lowering it’s value). It can improve the general case, improve speed, but decrease the upper limits of accuracy. Increasing sensitivity to black will do the same.

Credits

Many thanks to Fraser Hemphill for writing the original gradify project.

License

MIT

Metadata

Release files for gradify 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gradify 1.0.0
File Size Uploaded Provenance
gradify-1.0.0.tar.gz 5.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gradify 1.0.0
File Interpreter ABI Platform
gradify-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.0 kB

Release files / gradify-1.0.0.tar.gz

Download URL gradify-1.0.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bcceefebf6d06a1887b2d205f69ae6c9d3f444c7ea1d4c872e67c65a0b61ca7d
BLAKE2b-256 checksum
How to use checksums
6beb6b3b772a46de5a56c1c7a3d8cfcde1b7c878eebe1a4bdae9d8e9e7c26ccd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.13

Release files / gradify-1.0.0-py3-none-any.whl

Download URL gradify-1.0.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4fa7f1a74c9fdf97737dc9b96c936ee0646f2a047d8904496529e436e50909bc
BLAKE2b-256 checksum
How to use checksums
3be087c194842c513facaaf6ec960482278838e5a66700f0bc73589988880e7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.13

Security for gradify 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page