=============
image-blender
=============
``image-blender`` is a Python extension which provides a fast implementation of
Adobe Photoshop's blend modes. It is written using Cython. It was supposed to be
a helper module for psd-tools_ package back in 2015, but ended up in release hell
as I've lost an inspiration.
|Status| |PyPI|
.. _psd-tools: https://github.com/psd-tools/psd-tools
.. |Status| image:: https://img.shields.io/pypi/status/image-blender?label=Status
:alt: Development status
.. |PyPI| image:: https://img.shields.io/pypi/v/image-blender?label=PyPI
:target: https://pypi.org/project/image-blender/
:alt: PyPI version
Usage
-----
``image-blender`` is not a complete solution, it only provides you with blend
functions themselves, so you can blend two images together. You should use some
additional Python package to work with images and alpha-composite them (e.g.
Pillow_ or pymaging_).
.. _Pillow: https://github.com/python-pillow/Pillow
.. _pymaging: https://github.com/ojii/pymaging
There are some requirements that should be met to apply a blend function to a
pair of images:
1. Blend functions work with bytes, so you must pass a raw image data into them;
2. Both images must be in ``RGBA`` mode and have the same size;
3. Both images must have a bit depth of 32 bits (8 bits per channel).
Let's take a look at some use cases, but first let's define one helper
function and make some preparations. From now on it's assumed you're using
Pillow and all of the above requirements are already met:
.. code:: python
:number-lines:
from PIL import Image
import image_blender
def apply_opacity(im, opacity):
if opacity == 255:
return im
alpha_index = len(im.mode) - 1
a = im.split()[alpha_index]
opacity_scale = opacity / 255
a = a.point(lambda i: i * opacity_scale)
im.putalpha(a)
return im
image_bottom = Image.open("image1.png")
image_top = Image.open("image2.png")
opacity = 200
The above function applies a constant opacity to an image with existing
alpha channel. Now let's go to the examples:
* Blend two images using ``Normal`` mode with some opacity:
.. code:: python
:number-lines: 20
# apply opacity to the top image first...
image_top = apply_opacity(image_top, opacity)
# ... then simply alpha-composite them, no blend function is needed...
result = Image.alpha_composite(image_bottom, image_top)
result.save("normal_with_opacity.png")
* Blend two images using ``Multiply`` mode (without opacity):
.. code:: python
:number-lines: 20
# apply a blend function to a raw image data...
tmp_top_bytes = image_blender.multiply(image_bottom.tobytes(), image_top.tobytes())
# ... then create a new Image object from the resulting data...
# Note: Images' sizes are the same.
tmp_top = Image.frombytes("RGBA", image_top.size, tmp_top_bytes)
# ... finally, alpha-composite a new top image with a bottom one...
#
# Note: In these examples images have an alpha channel.
# That's why we still need to alpha-composite them!
result = Image.alpha_composite(image_bottom, tmp_top)
result.save("multiply.png")
* Blend two images using ``Multiply`` mode with some opacity:
.. code:: python
:number-lines: 20
# simply combine the above examples...
image_top = apply_opacity(image_top, opacity)
tmp_top_bytes = image_blender.multiply(image_bottom.tobytes(), image_top.tobytes())
tmp_top = Image.frombytes("RGBA", image_top.size, tmp_top_bytes)
result = Image.alpha_composite(image_bottom, tmp_top)
result.save("multiply_with_opacity.png")
* Blend two images using ``Dissolve`` mode with some opacity:
.. code:: python
:number-lines: 20
image_top = apply_opacity(image_top, opacity)
result_bytes = image_blender.dissolve(image_bottom.tobytes(), image_top.tobytes())
result = Image.frombytes("RGBA", image_top.size, result_bytes)
# This one is a bit different here:
# you should NOT alpha-composite the images when using Dissolve mode!
result.save("dissolve_with_opacity.png")
License
-------
Copyright 2015-2023 Evgeny Kopylov. Licensed under the `MIT License`_.
.. _`MIT License`: https://github.com/psd-tools/image-blender/blob/master/LICENSE.txt
Raw data
{
"_id": null,
"home_page": "https://github.com/psd-tools/image-blender",
"name": "image-blender",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "photoshop,layers,images,blending,composition,chops,imagechops",
"author": "Evgeny Kopylov",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/39/c5/b0f423e5c2a73c6b15cf92c4b2ad5a7a9fb9affe388e8b9ae09ea083f2b5/image-blender-0.1.1.tar.gz",
"platform": null,
"description": "=============\nimage-blender\n=============\n\n``image-blender`` is a Python extension which provides a fast implementation of\nAdobe Photoshop's blend modes. It is written using Cython. It was supposed to be\na helper module for psd-tools_ package back in 2015, but ended up in release hell\nas I've lost an inspiration.\n\n|Status| |PyPI|\n\n.. _psd-tools: https://github.com/psd-tools/psd-tools\n\n.. |Status| image:: https://img.shields.io/pypi/status/image-blender?label=Status\n :alt: Development status\n\n.. |PyPI| image:: https://img.shields.io/pypi/v/image-blender?label=PyPI\n :target: https://pypi.org/project/image-blender/\n :alt: PyPI version\n\nUsage\n-----\n``image-blender`` is not a complete solution, it only provides you with blend\nfunctions themselves, so you can blend two images together. You should use some\nadditional Python package to work with images and alpha-composite them (e.g.\nPillow_ or pymaging_).\n\n.. _Pillow: https://github.com/python-pillow/Pillow\n.. _pymaging: https://github.com/ojii/pymaging\n\nThere are some requirements that should be met to apply a blend function to a\npair of images:\n\n1. Blend functions work with bytes, so you must pass a raw image data into them;\n2. Both images must be in ``RGBA`` mode and have the same size;\n3. Both images must have a bit depth of 32 bits (8 bits per channel).\n\nLet's take a look at some use cases, but first let's define one helper\nfunction and make some preparations. From now on it's assumed you're using\nPillow and all of the above requirements are already met:\n\n.. code:: python\n :number-lines:\n\n from PIL import Image\n import image_blender\n\n def apply_opacity(im, opacity):\n if opacity == 255:\n return im\n\n alpha_index = len(im.mode) - 1\n a = im.split()[alpha_index]\n opacity_scale = opacity / 255\n a = a.point(lambda i: i * opacity_scale)\n im.putalpha(a)\n return im\n\n image_bottom = Image.open(\"image1.png\")\n image_top = Image.open(\"image2.png\")\n\n opacity = 200\n\nThe above function applies a constant opacity to an image with existing\nalpha channel. Now let's go to the examples:\n\n* Blend two images using ``Normal`` mode with some opacity:\n\n .. code:: python\n :number-lines: 20\n\n # apply opacity to the top image first...\n image_top = apply_opacity(image_top, opacity)\n # ... then simply alpha-composite them, no blend function is needed...\n result = Image.alpha_composite(image_bottom, image_top)\n\n result.save(\"normal_with_opacity.png\")\n\n* Blend two images using ``Multiply`` mode (without opacity):\n\n .. code:: python\n :number-lines: 20\n\n # apply a blend function to a raw image data...\n tmp_top_bytes = image_blender.multiply(image_bottom.tobytes(), image_top.tobytes())\n # ... then create a new Image object from the resulting data...\n # Note: Images' sizes are the same.\n tmp_top = Image.frombytes(\"RGBA\", image_top.size, tmp_top_bytes)\n # ... finally, alpha-composite a new top image with a bottom one...\n #\n # Note: In these examples images have an alpha channel.\n # That's why we still need to alpha-composite them!\n result = Image.alpha_composite(image_bottom, tmp_top)\n\n result.save(\"multiply.png\")\n\n* Blend two images using ``Multiply`` mode with some opacity:\n\n .. code:: python\n :number-lines: 20\n\n # simply combine the above examples...\n image_top = apply_opacity(image_top, opacity)\n tmp_top_bytes = image_blender.multiply(image_bottom.tobytes(), image_top.tobytes())\n tmp_top = Image.frombytes(\"RGBA\", image_top.size, tmp_top_bytes)\n result = Image.alpha_composite(image_bottom, tmp_top)\n\n result.save(\"multiply_with_opacity.png\")\n\n* Blend two images using ``Dissolve`` mode with some opacity:\n\n .. code:: python\n :number-lines: 20\n\n image_top = apply_opacity(image_top, opacity)\n result_bytes = image_blender.dissolve(image_bottom.tobytes(), image_top.tobytes())\n result = Image.frombytes(\"RGBA\", image_top.size, result_bytes)\n # This one is a bit different here:\n # you should NOT alpha-composite the images when using Dissolve mode!\n\n result.save(\"dissolve_with_opacity.png\")\n\nLicense\n-------\nCopyright 2015-2023 Evgeny Kopylov. Licensed under the `MIT License`_.\n\n.. _`MIT License`: https://github.com/psd-tools/image-blender/blob/master/LICENSE.txt",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Python extension which provides a fast implementation of Adobe Photoshop's blend modes",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/psd-tools/image-blender"
},
"split_keywords": [
"photoshop",
"layers",
"images",
"blending",
"composition",
"chops",
"imagechops"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "39c5b0f423e5c2a73c6b15cf92c4b2ad5a7a9fb9affe388e8b9ae09ea083f2b5",
"md5": "09193e16d74eafc3044e09562203a8b1",
"sha256": "5169cc78a7c91b176055a612b41bb44eb6fa0704174eed8eba690947165400d1"
},
"downloads": -1,
"filename": "image-blender-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "09193e16d74eafc3044e09562203a8b1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 41672,
"upload_time": "2023-08-18T08:01:24",
"upload_time_iso_8601": "2023-08-18T08:01:24.438447Z",
"url": "https://files.pythonhosted.org/packages/39/c5/b0f423e5c2a73c6b15cf92c4b2ad5a7a9fb9affe388e8b9ae09ea083f2b5/image-blender-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-18 08:01:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "psd-tools",
"github_project": "image-blender",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "image-blender"
}