{"id":15760605,"url":"https://github.com/flrs/blend_modes","last_synced_at":"2025-04-08T02:36:28.752Z","repository":{"id":57415579,"uuid":"73294031","full_name":"flrs/blend_modes","owner":"flrs","description":"Python package that implements image blend modes","archived":false,"fork":false,"pushed_at":"2024-10-16T22:05:31.000Z","size":5367,"stargazers_count":144,"open_issues_count":8,"forks_count":29,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-01T01:36:42.960Z","etag":null,"topics":["blend-images","blend-modes","blending","gimp","image-blending","photoshop","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flrs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-09T15:03:07.000Z","updated_at":"2025-02-24T23:17:50.000Z","dependencies_parsed_at":"2024-06-18T18:35:16.246Z","dependency_job_id":"22b27a9c-ddbc-4d6a-bd76-9e64a61df0a2","html_url":"https://github.com/flrs/blend_modes","commit_stats":{"total_commits":73,"total_committers":5,"mean_commits":14.6,"dds":"0.17808219178082196","last_synced_commit":"4eca9470a210049db32b3fd2e95cc17d5b58e7bc"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flrs%2Fblend_modes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flrs%2Fblend_modes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flrs%2Fblend_modes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flrs%2Fblend_modes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flrs","download_url":"https://codeload.github.com/flrs/blend_modes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247765461,"owners_count":20992314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blend-images","blend-modes","blending","gimp","image-blending","photoshop","python"],"created_at":"2024-10-04T10:59:13.136Z","updated_at":"2025-04-08T02:36:28.719Z","avatar_url":"https://github.com/flrs.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![PyPI version](https://badge.fury.io/py/blend-modes.svg)](https://badge.fury.io/py/blend-modes)\n[![Conda-forge version](https://img.shields.io/conda/vn/conda-forge/blend_modes.svg)](https://anaconda.org/conda-forge/blend_modes)\n[![Documentation Status](https://readthedocs.org/projects/blend-modes/badge/?version=latest)](https://blend-modes.readthedocs.io/en/latest/?badge=latest)\n[![Build Status](https://dev.azure.com/florianroscheck/blend_modes/_apis/build/status/flrs.blend_modes?branchName=master)](https://dev.azure.com/florianroscheck/blend_modes/_build/latest?definitionId=1\u0026branchName=master)\n\nBlend Modes\n===========\nThis Python package implements blend modes for images.\n\n**⚠️ This project is no longer maintained. Are you interested in maintaining it? Please file let us know [here](https://github.com/flrs/blend_modes/issues/28). ⚠️**\n\nDescription\n-----------\nThe Blend Modes package enables blending different images, or image layers, by means of blend modes. These modes are commonly found in graphics programs like [Adobe Photoshop](http://www.adobe.com/Photoshop) or [GIMP](https://www.gimp.org/).\n\nBlending through blend modes allows to mix images in a variety of ways. This package currently supports the following blend modes (name of the respective functions in the package in `italics`):\n\n* Soft Light (`blend_modes.soft_light`)\n* Lighten Only (`blend_modes.lighten_only`)\n* Dodge (`blend_modes.dodge`)\n* Addition (`blend_modes.addition`)\n* Darken Only (`blend_modes.darken_only`)\n* Multiply (`blend_modes.multiply`)\n* Hard Light (`blend_modes.hard_light`)\n* Difference (`blend_modes.difference`)\n* Subtract (`blend_modes.subtract`)\n* Grain Extract (known from GIMP, `blend_modes.grain_extract`)\n* Grain Merge (known from GIMP, `blend_modes.grain_merge`)\n* Divide (`blend_modes.divide`)\n* Overlay (`blend_modes.overlay`)\n* Normal (`blend_modes.normal`)\n\nThe intensity of blending can be controlled by means of an *opacity* parameter that is passed into the functions. See [Usage](#usage) for more information.\n\nThe Blend Modes package is optimized for speed. It takes advantage of vectorization through Numpy. Further speedup can be achieved when implementing the package in Cython. However, Cython implementation is not part of this package.\n\nInstallation\n------------\nThe Blend Modes package can be installed through pip:\n\n```pip install blend_modes```\n\nor conda:\n\n```conda install -c conda-forge blend_modes```\n\nUsage\n-----\nThe blend mode functions take image data expressed as arrays as an input. These image data are usually obtained through functions from image processing packages. Two popular image processing packages in Python are [PIL](https://pypi.python.org/pypi/PIL) or its fork [Pillow](https://pypi.python.org/pypi/Pillow/) and [OpenCV](http://opencv.org/). The examples in this chapter show how to blend images using these packages.\n \n### Input and Output Formats\n\nA typical blend mode operation is called like this:\n\n```python\nblended_img = soft_light(bg_img, fg_img, opacity)\n```\n\nThe blend mode functions expect [Numpy](https://pypi.python.org/pypi/numpy) float arrays in the format [*pixels in dimension 1*,*pixels in dimension 2*,4] as an input. Both images needs to have the same size, so the *pixels in dimension 1* must be the same for `bg_img` and `fg_img`. Same applies to the *pixels in dimension 2*. Thus, a valid shape of the arrays would be `bg_img.shape == (640,320,4)` and `fg_img.shape == (640,320,4)`.\n\nThe order of the channels in the third dimension should be *R, G, B, A*, where *A* is the alpha channel. All values should be *floats* in the range *0.0 \u003c= value \u003c= 255.0*.\n\nThe blend mode functions return arrays in the same format as the input format.\n\n### Examples\n\nThe following examples show how to use the Blend Modes package in typical applications.\n\nThe examples are structured in three parts:\n\n 1. Load background and foreground image. The foreground image is to be blended onto the background image.\n \n 2. Use the Blend Modes package to blend the two images via the \"soft light\" blend mode.\n    The package supports multiple blend modes. See the [Description](#description) for a full list.\n    \n 3. Display the blended image.\n\n#### PIL/Pillow Example\nThe following example shows how to use the Blend Modes package with the [PIL](https://pypi.python.org/pypi/PIL) or [Pillow](https://pypi.python.org/pypi/Pillow/) packages.\n \n```python\nfrom PIL import Image\nimport numpy\nfrom blend_modes import soft_light\n\n# Import background image\nbackground_img_raw = Image.open('background.png')  # RGBA image\nbackground_img = numpy.array(background_img_raw)  # Inputs to blend_modes need to be numpy arrays.\nbackground_img_float = background_img.astype(float)  # Inputs to blend_modes need to be floats.\n\n# Import foreground image\nforeground_img_raw = Image.open('foreground.png')  # RGBA image\nforeground_img = numpy.array(foreground_img_raw)  # Inputs to blend_modes need to be numpy arrays.\nforeground_img_float = foreground_img.astype(float)  # Inputs to blend_modes need to be floats.\n\n# Blend images\nopacity = 0.7  # The opacity of the foreground that is blended onto the background is 70 %.\nblended_img_float = soft_light(background_img_float, foreground_img_float, opacity)\n\n# Convert blended image back into PIL image\nblended_img = numpy.uint8(blended_img_float)  # Image needs to be converted back to uint8 type for PIL handling.\nblended_img_raw = Image.fromarray(blended_img)  # Note that alpha channels are displayed in black by PIL by default.\n                                                # This behavior is difficult to change (although possible).\n                                                # If you have alpha channels in your images, then you should give\n                                                # OpenCV a try.\n\n# Display blended image\nblended_img_raw.show()\n```\n\n#### OpenCV Example\nThe following example shows how to use the Blend Modes package with [OpenCV](http://opencv.org/).\n \n```python\nimport cv2  # import OpenCV\nimport numpy\nfrom blend_modes import soft_light\n\n# Import background image\nbackground_img_float = cv2.imread('background.png',-1).astype(float)\n\n# Import foreground image\nforeground_img_float = cv2.imread('foreground.png',-1).astype(float)\n\n# Blend images\nopacity = 0.7  # The opacity of the foreground that is blended onto the background is 70 %.\nblended_img_float = soft_light(background_img_float, foreground_img_float, opacity)\n\n# Display blended image\nblended_img_uint8 = blended_img_float.astype(numpy.uint8)  # Convert image to OpenCV native display format\ncv2.imshow('window', blended_img_uint8)\ncv2.waitKey()  # Press a key to close window with the image.\n```\n\nDocumentation\n-------------\nFull documentation for the latest version of this package is available on [Read the Docs](https://blend-modes.readthedocs.io/en/latest/).\n\nDependencies\n------------\nThe Blend Modes package needs [Numpy](https://pypi.python.org/pypi/numpy) to function correctly. For loading images the following packages have been successfully used:\n \n * [PIL](https://pypi.python.org/pypi/PIL)\n * [Pillow](https://pypi.python.org/pypi/Pillow/)\n * [OpenCV](http://opencv.org/)\n\nSee Also\n--------\nBlend modes are further described on [Wikipedia](https://en.wikipedia.org/wiki/Blend_modes). An actual implementation can be found in the [GIMP source code](https://gitlab.gnome.org/GNOME/gimp/blob/master/app/operations/layer-modes-legacy/gimpoperationdividelegacy.c).\n\nContribution\n------------\nI am happy about any contribution or feedback. Please let me know about your comments via the Issues tab on [GitHub](https://github.com/flrs/blend_modes/issues).\n\nLicense\n-------\nThe Blend Modes package is distributed under the [MIT License (MIT)](https://github.com/flrs/blend_modes/blob/master/LICENSE.txt). Please also take note of the licenses of the dependencies.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflrs%2Fblend_modes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflrs%2Fblend_modes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflrs%2Fblend_modes/lists"}