Add dash parameter for line, polygon, and rectangle drawing#9490
Open
Krishnachaitanyakc wants to merge 5 commits intopython-pillow:mainfrom
Open
Add dash parameter for line, polygon, and rectangle drawing#9490Krishnachaitanyakc wants to merge 5 commits intopython-pillow:mainfrom
Krishnachaitanyakc wants to merge 5 commits intopython-pillow:mainfrom
Conversation
Add a `dash` parameter to `ImageDraw.line()`, `ImageDraw.polygon()`, and `ImageDraw.rectangle()` methods that allows drawing dashed outlines. The dash pattern follows the SVG `stroke-dasharray` specification: - Accepts a tuple of ints specifying alternating drawn/blank segment lengths - Odd-length patterns are automatically doubled per the SVG spec - The dash pattern is continuous across connected line segments and polygon edges - Empty dash tuples raise ValueError Closes python-pillow#9127
for more information, see https://pre-commit.ci
- Annotate pixels_used as float to fix float/int assignment mismatch - Rename redefined 'points' variable to 'joint_points' in curve joint code - Cast flat xy to Sequence[float] before slicing to fix type compatibility
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
dashparameter toImageDraw.line(),ImageDraw.polygon(), andImageDraw.rectangle()that enables drawing dashed outlines, implemented in the Python layer.stroke-dasharrayspecification: a tuple of ints specifying alternating drawn/blank segment lengths (e.g.(10, 5)draws 10px, skips 5px, repeats)ValueErrordashis not specifiedExample usage
Closes #9127
Test plan
test_imagedraw.pytests continue to pass (backward compatibility verified)versionadded:: 12.2.0