Skip to content

Commit 3161650

Browse files
committed
more docs
1 parent 6b51464 commit 3161650

File tree

8 files changed

+49
-9
lines changed

8 files changed

+49
-9
lines changed

blendmodes/blend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def blend(background: np.ndarray, foreground: np.ndarray, blendType: BlendType)
467467
def blendLayers(
468468
background: Image.Image,
469469
foreground: Image.Image,
470-
blendType: BlendType | tuple[str, ...],
470+
blendType: BlendType,
471471
opacity: float = 1.0,
472472
offsets: tuple[int, int] = (0, 0),
473473
) -> Image.Image:
@@ -629,7 +629,7 @@ def alpha_comp_shell(
629629
upper_alpha: np.ndarray,
630630
lower_rgb: np.ndarray,
631631
upper_rgb: np.ndarray,
632-
blendType: BlendType | tuple[str, ...],
632+
blendType: BlendType,
633633
) -> tuple[np.ndarray, np.ndarray]:
634634
"""
635635
Implement common transformations occurring in any blend or composite mode.

circle_silhouette.png

2.21 KB
Loading

documentation/reference/blendmodes/blend.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,14 @@ def alpha_comp_shell(
146146
upper_alpha: np.ndarray,
147147
lower_rgb: np.ndarray,
148148
upper_rgb: np.ndarray,
149-
blendType: BlendType | tuple[str, ...],
149+
blendType: BlendType,
150150
) -> tuple[np.ndarray, np.ndarray]: ...
151151
```
152152

153+
#### See also
154+
155+
- [BlendType](./blendtype.md#blendtype)
156+
153157

154158

155159
## blend
@@ -253,12 +257,16 @@ Blend two layers with custom opacity and offsets
253257
def blendLayers(
254258
background: Image.Image,
255259
foreground: Image.Image,
256-
blendType: BlendType | tuple[str, ...],
260+
blendType: BlendType,
257261
opacity: float = 1.0,
258262
offsets: tuple[int, int] = (0, 0),
259263
) -> Image.Image: ...
260264
```
261265

266+
#### See also
267+
268+
- [BlendType](./blendtype.md#blendtype)
269+
262270

263271

264272
## blendLayersArray

documentation/tutorials/README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
11
# Getting Started - Examples
22

3-
Be sure to include the following for the functions below
3+
Below, you'll find practical examples to help you get started with blending/compositing
4+
images with the `blendmodes` library. Whether you're experimenting with simple overlays
5+
or crafting intricate compositions, these examples will guide you through the process.
6+
7+
To begin, let’s take a look at our two source images:
48

59
![Rainbow](../../tests/data/src/rainbow.png)
610
![Duck](../../tests/data/src/duck.png)
711

12+
We'll use these images as our **background** and **foreground** in the examples below.
13+
14+
To blend two images together, use the `blendLayers` function with your chosen blend mode:
15+
816
```python
917
from blendmodes.blend import blendLayers, BlendType
1018

1119
background = Image.open(THISDIR + "/rainbow.png")
1220
foreground = Image.open(THISDIR + "/duck.png")
1321
```
1422

15-
## Normal
23+
Blend modes define how the **foreground** interacts with the **background**. Let’s start with the most fundamental mode:
24+
25+
## **Normal**
26+
27+
The **Normal** blend mode places the foreground image on top of the background without
28+
any additional blending effects.
1629

1730
```python
1831
blendLayers(background, foreground, BlendType.NORMAL)
1932
```
2033

21-
![Normal](../../tests/data/case1/normal_expected.png)
34+
Further examples of different blend types using `rainbow.png` and `duck.png` are as below
35+
36+
Note: for other composition examples (without code snippets), check out the [extended blend mode examples](blend_examples.md).
2237

2338
## Multiply
2439

34.6 KB
Loading

rectangle_silhouette.png

1.48 KB
Loading

tests/data/src/genimgs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ def create_silhouette(shape:str="circle") -> Image.Image:
5555
img = Image.new("RGBA", size=(400, 400), color=(255, 255, 255, 0))
5656
draw = ImageDraw.Draw(img)
5757
if shape == "circle":
58-
draw.ellipse((100, 100, 300, 300), fill=(0, 0, 0, 255))
58+
draw.ellipse((100, 100, 300, 300), fill=(50, 0, 50, 255))
5959
elif shape == "rectangle":
60-
draw.rectangle((100, 150, 300, 350), fill=(0, 0, 0, 255))
60+
draw.rectangle((100, 150, 300, 350), fill=(50, 0, 50, 255))
6161
img.save(f"{shape}_silhouette.png")
6262
return img
6363

tests/test_main.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,20 @@ def test_non_rgba() -> None:
9090
background = Image.open(THISDIR / "data/src/rainbow.jpg")
9191
foreground = Image.open(THISDIR / "data/src/duck.jpg")
9292
blendLayers(background, foreground, BlendType.NORMAL)
93+
94+
95+
if __name__ == "__main__":
96+
for dest_filename, _ in BLEND_TESTS:
97+
blend_mode = dest_filename.split("_")[0]
98+
blend_mode = blend_mode[0].upper() + blend_mode[1:]
99+
100+
print(f"""
101+
## {blend_mode}
102+
103+
| Case | Background | Foreground | Output |
104+
|------|---------|------|--------|
105+
| Case 1 | ![img](../../tests/data/src/rainbow.png) | ![img](../../tests/data/src/duck.png) | ![img](../../tests/data/case1/{dest_filename}) |
106+
| Case 2 | ![img](../../tests/data/src/noise_texture.png) | ![img](../../tests/data/src/red_soft_mask.png) | ![img](../../tests/data/case2/{dest_filename}) |
107+
| Case 2 | ![img](../../tests/data/src/red_soft_mask.png) | ![img](../../tests/data/src/rectangle_silhouette.png) | ![img](../../tests/data/case3/{dest_filename}) |
108+
109+
""") # noqa: T201, E501

0 commit comments

Comments
 (0)