Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix watermark bug2 #144

Merged
merged 2 commits into from
Oct 17, 2022
Merged

Fix watermark bug2 #144

merged 2 commits into from
Oct 17, 2022

Conversation

tingxin
Copy link

@tingxin tingxin commented Oct 13, 2022

hot fix bug: the text was cut
root cause: the text width does not been calculate right due to some especial char
hot fix way: improve the calculate way to especial char

@wchaws
Copy link
Owner

wchaws commented Oct 13, 2022

@tingxin
svg "text-anchor" 可以让你避免计算文字宽度 https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/text-anchor

  <text text-anchor="start" x="60" y="40">A</text>
  <text text-anchor="middle" x="60" y="75">A</text>
  <text text-anchor="end" x="60" y="110">A</text>

image

高度方向用 baseline-shift 看这个例子:https://github.com/wchaws/sharp-text/blob/main/index.js

  <text
  x="0" y="500"
  fill="white"
  text-anchor="start"
  font-size="80px"
  baseline-shift="15%"
  font-family="Open Sans"
  >
  中 sw
  </text>


2022/10/17 updates

Sharp 增加了 text API lovell/sharp#512 (comment) 看上去这个方案可以完美解决我们的问题

参考链接:

@wchaws wchaws merged commit 4f75807 into wchaws:master Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants