Gradientify is a powerful command-line tool that replaces image backgrounds with stunning gradients and shader-based patterns. Perfect for making jigs less boring, especially with images where there are lone subjects and/or the background is very dull. This tool will make those images more entertaining for online jigsaw puzzles. You could also use this tool for whatever.
Features
🎨 Multiple background styles: Linear gradients, liquid effects, topographic maps, spirals and more
✨ AI Cutout: Remove backgrounds from images. Powered by [rembg](https://github.com/danielgatis/rembg)
🖼️ Transparency support: Preserve existing transparency or replace only transparent areas
🧪 Mask refinement: Clean up edges with morphological operations
🔄 Batch processing: Process multiple images at once
🏷️ Preset gradients: Choose from a vast range of (semi)professionally designed color schemes
🎚️ User Provided or Custom gradients: Pass your own color combinations or even have your own library of gradients
📐 Orientation control: Adjust gradient direction
Clone the repository:
git clone https://github.com/yourusername/gradientify.git
cd gradientifypython -m venv .venv
source .venv/bin/activate # On Windows use .venv\Scripts\activate
pip install -r requirements.txtIt's highly recommended your images to be in PNG format and have transparency already. If it doesn't, you can use the script's AI image cutout feature for background removal. It also has a fallback dumb background remover but is not recommended. Read on for more details. If the image doesn't uphold a quality transparency to your tastes, consider the following:
- Use this script with a different AI model: check out available models at rembg's documentation. You can specify a different model using the
--modeloption. NOTE: models are downloaded automatically, be aware they can be large (hundreds of MBs). - Use an online background remover: Websites like
withoutbg.comorpixlr.comcan automatically remove backgrounds from images, making them transparent. - Ask the original creator: If you have access to the original image files, ask the creator to provide a version with a transparent background.
- If you get your images from imageboards like
gelbooru.comyou can use the tagtransparent_backgroundor similar to have transparency from origin. - Use a photo editing tool: Open your image in software like Photoshop, GIMP, Krita or an online editor. Use the magic wand or lasso tool to select the background and delete it, leaving a transparent layer.
- Once you have your images with transparency already included, use the tool with the
--only-transparentor-otoption to replace only the transparent areas with gradients or patterns.
The script includes an AI-powered background removal feature that works well for images with clear subjects. It is turned on by default. It uses the rembg library to automatically detect and remove backgrounds, it works pretty well for most images but is not perfect.
Features:
- Uses rembg for AI-powered background removal.
- The script will try to detect if a image with the postfix "_transparent.png" already exists, and if it does, it will skip the background removal step.
- If your image is already transparent, you can use the
--only-transparentor-otoption to replace only the transparent areas with gradients or patterns. - The script will save the resulting transparent image with the postfix "_transparent.png" in the same directory as the original image.
Replace background with default gradient, will remove background automatically:
python main.py image.pngUse a specific preset gradient, using an image with transparency included:
python main.py --gradient sunset -ot image.pngUse topographic style with ocean bliss gradient:
python main.py --style topographic --gradient oceanbliss image.pngBatch Processing
Process all images in current directory:
python main.pyProcess specific images with custom settings:
python main.py --style liquid --gradient fireandice -ot image1.png image2.jpg-
Linear/Barycentric (Gradient): Creates smooth color transitions. Supports linear (2 colors) and barycentric (3 colors) gradients.

-
Mesh (Gradient): Creates complex, multicolor transitions across a shape by creating a grid of random nodes. Supports 2-3 colors.

-
Liquid: Organic, flowing patterns that simulate liquid movements. Requires exactly 2 colors.

-
Voronoi: Cellular patterns based on Voronoi diagrams. Creates a geometric, tech-inspired look.

-
Topographic: Contour map-like patterns that simulate elevation. Works best with 2-4 colors.

-
Spiral: Hypnotic spiral patterns that create visual depth. Requires exactly 2 colors.

-
Squiggle: Playful squiggly line patterns that add artistic flair. Supports 2-4 colors.

-
Scales: Scales create a fish-like texture with overlapping shapes. Requires 2 or 3 colors.

-
Watercolor: Soft, blended patterns that mimic watercolor painting. Requires 2 or 3 colors.

-
Hexagons3d: Creates a 3D hexagonal pattern that adds depth and complexity. Requires 2 or 3 colors.

-
Triwedges: Triwedges create a triangular tessellation pattern that adds geometric interest. Requires 2 or 3 colors.

-
Cacti: Cacti, desert-inspired pattern with overlapping shapes. Requires 2 or 3 colors.

To check out all available options, run the following command:
python main.py --helpYou can provide your own gradients using the following JSON format:
{
"my_custom_gradient_2": ["#ff0000", "#00ff00"],
"my_custom_gradient_3": ["#ff0000", "#00ff00", "#0000ff"]
}Then, you can pass your custom gradients passing this JSON file using the --user-gradients option:
python main.py --user-gradients mypresets.json --gradient my_custom_gradient_2 image.pngWhen you let the script choose random gradients, you can choose between either combine them with script's preset gradients or to only use your gradients by passing either --combine-presets or --only-user-gradients respectively:
# Leaving it defaults to combine both, although you can also use --combine-presets to be explicit
python main.py image.png -ot
# Only use your gradients
python main.py --only-user-gradients image.png -otCurrently, the program supports only 2-3 color gradients.
Contributions are welcome! Please open an issue or pull request for:
New gradient presets
Additional shader styles
Performance improvements
Documentation enhancements

