Video editing with Python
Fix 'video.tools.drawing.color_gradient' (#1467)
Álvaro Mondéjar7183eaa107b8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bc319691..be6e7ac3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- Fixed `freeze` FX was freezing at time minus 1 second as the end [\#1461](https://github.com/Zulko/moviepy/pull/1461)- `AudioClip.max_volume(stereo=True)` now can return more than 2 channels [\#1464](https://github.com/Zulko/moviepy/pull/1464)- Fixed `Clip.cutout` transformation not being applied to audio [\#1468](https://github.com/Zulko/moviepy/pull/1468)+- Fixed arguments inconsistency in `video.tools.drawing.color_gradient` [\#1467](https://github.com/Zulko/moviepy/pull/1467)## [v2.0.0.dev2](https://github.com/zulko/moviepy/tree/v2.0.0.dev2) (2020-10-05)diff --git a/moviepy/video/tools/drawing.py b/moviepy/video/tools/drawing.pyindex 59b150b1..02b24ee2 100644--- a/moviepy/video/tools/drawing.py+++ b/moviepy/video/tools/drawing.py@@ -102,6 +102,8 @@ def color_gradient(if shape == "bilinear":if vector is None:+ if p2 is None:+ raise ValueError("You must provide either 'p2' or 'vector'")vector = np.array(p2) - np.array(p1)m1, m2 = [@@ -124,20 +126,18 @@ def color_gradient(p1 = np.array(p1[::-1]).astype(float)- if vector is None and p2:- p2 = np.array(p2[::-1])- vector = p2 - p1- else:- vector = np.array(vector[::-1])- p2 = p1 + vector-- if vector is not None:- norm = np.linalg.norm(vector)-M = np.dstack(np.meshgrid(range(w), range(h))[::-1]).astype(float)if shape == "linear":+ if vector is None:+ if p2 is not None:+ vector = np.array(p2[::-1]) - p1+ else:+ raise ValueError("You must provide either 'p2' or 'vector'")+ else:+ vector = np.array(vector[::-1])+ norm = np.linalg.norm(vector)n_vec = vector / norm ** 2 # norm 1/norm(vector)p1 = p1 + offset * vector@@ -148,10 +148,7 @@ def color_gradient(return arr * color_1 + (1 - arr) * color_2elif shape == "radial":- if radius is None:- radius = norm-- if radius == 0:+ if (radius or 0) == 0:arr = np.ones((h, w))else:arr = (np.sqrt(((M - p1) ** 2).sum(axis=2))) - offset * radius@@ -161,6 +158,7 @@ def color_gradient(if color_1.size > 1:arr = np.dstack(3 * [arr])return (1 - arr) * color_1 + arr * color_2+ raise ValueError("Invalid shape, should be either 'radial', 'linear' or 'bilinear'")def color_split(