Skip to main content

A python library to generate CSS gradient from an image

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gradify-0.3.3.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

gradify-0.3.3-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file gradify-0.3.3.tar.gz.

File metadata

  • Download URL: gradify-0.3.3.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for gradify-0.3.3.tar.gz
Algorithm Hash digest
SHA256 af3eb7c12f5a86ac625debddee4c8f728d959085cba8f7cca8b8fbb650fcc813
MD5 0a239611d9848b1615a8358942506a73
BLAKE2b-256 553ade035ed869698bb016793e022ceee56d16816b6e47657b7363ad0b9d4a59

See more details on using hashes here.

File details

Details for the file gradify-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: gradify-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for gradify-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 68e7f0218bacc262e2b2db3a89f623749b2cab3fecc77062ffe281feb7088b7c
MD5 28b94c5bb607133868850ffa15edb96b
BLAKE2b-256 a2e0f61879e794d7e48230fb6b7f4eb812bc8740c3a1a6737b33ff10dfa9bd1c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page