Use fractional coordinates when drawing text #6722
Merged
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.
Resolves #3977
That issue attempts to draw two halves of a word separately, expecting them to occupy the same pixels as the complete word. The example given there is "par" and "adise" vs "paradise".
#4959 helped by adding
textlength
, but did not resolve the issue completely. After switching totextlength
, there was still a difference.The ImageDraw text operation essentially has two parts - it generates a
mask
from the text characters with no awareness of the text position, and then pastes that mask onto the image at the relevant position. I had a thought - what if the position did matter, and text characters were rendered differently if they started halfway through a pixel?With this PR, I have added a
start
argument togetmask
andgetmask2
.produces "a", "d", "s" and "e" in the same location, but a different "i" for the first line compared to the second.
Changing ImageDraw's
text
method to pass through the fractional coordinates of the text resolves the issue, allowing "par" and "adise" to fill the same pixels as "paradise".To try and future proof the API, I have set
start
to be a tuple, so that both horizontal and vertical starting positions can be specified.