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

Screenshot offset problem, to solve. Refer to the following screenshot for details: #2769

Open
webstager opened this issue Dec 12, 2021 · 16 comments · May be fixed by #2835
Open

Screenshot offset problem, to solve. Refer to the following screenshot for details: #2769

webstager opened this issue Dec 12, 2021 · 16 comments · May be fixed by #2835

Comments

@webstager
Copy link

I’m using the latest1.3.3

Bug reports:

Before screenshot

image

After screenshot

image

Specifications:

  • html2canvas version tested with:
  • Browser & version: Google Chrome 95.0.4638.69
  • Operating system: macos
@Srn5333
Copy link

Srn5333 commented Dec 24, 2021

Modify body line-height
GFK6D%$NS4X QNMTI55UW}B
image

@webstager
Copy link
Author

Hello, I tried, but I still can't.

@webstager
Copy link
Author

Hello, I tried, but I still can't.

Before screenshot
image

After screenshot
image

@shinokada
Copy link

shinokada commented Dec 26, 2021

I used line-height: 0 !important; in body.
And reset line-height for other class/div.

It is very hacky. I hope the author is going to fix it soon.

@webstager
Copy link
Author

I used line-height: 0 !important; in body. And reset line-height for other class/div.

It is very hacky. I hope the author is going to fix it soon.

same hope.

@niklasvh
Copy link
Owner

Could you please share a repro on jsfiddle.net?

@webstager
Copy link
Author

webstager commented Jan 9, 2022

Could you please share a repro on jsfiddle.net?

Hello, you can add placeholder text in input. Then use html2canvas to generate and see the performance. It will have text position offset. Reference Repro:
https://codepen.io/xiang0308/pen/rNGZzGV

Please click download it to compare the position change of placeholder text before and after the image generated by html2canvas.

@808brinks
Copy link

808brinks commented Jan 11, 2022

Another reproduction 1.3.4: https://jsfiddle.net/6dfwc034/1/
In the screenshot you can see the text in the badge is shifted down by 1 or 2 pixels.

And reproduction for 1.4.0: https://jsfiddle.net/6dfwc034/2/

In my actual project the shift down is a lot more than the few pixels here but i'm not sure what is the cause of that.

@ohaibbq ohaibbq linked a pull request Feb 18, 2022 that will close this issue
7 tasks
@sunnilyliu
Copy link

调整body line-height GFK6D%$NS4X QNMTI55UW}B 图片

调整body line-height GFK6D%$NS4X QNMTI55UW}B 图片

有用 可以解决

@webstager
Copy link
Author

调整body line-height GFK6D%$NS4X QNMTI55UW}B 图片

调整body line-height GFK6D%$NS4X QNMTI55UW}B 图片

有用 可以解决

你好,试了,不行。input框内的placeholder文本默认居中显示,但截图后依然发生偏移。
可参考我的codepen示例: https://codepen.io/xiang0308/pen/rNGZzGV

@danielwong2268
Copy link

Any updates on this? Looks like there's several tickets opened regarding a similar issue, and some open PRs that might fix.

@johanazhu
Copy link

same question

@prasid444
Copy link

Some PR claims that this error is fixed, but it's not merged yet. Any updates?

@rsq1259
Copy link

rsq1259 commented Nov 7, 2022

Hello, I tried, but I still can't.

Before screenshot image

After screenshot image

一样的问题,你最后解决了吗

@webstager
Copy link
Author

Hello, I tried, but I still can't.

Before screenshot image
After screenshot image

一样的问题,你最后解决了吗

h2c没有解决,最后换方案了,用webrtc解决了

@rsq1259
Copy link

rsq1259 commented Nov 17, 2022

Hello, I tried, but I still can't.

Before screenshot image
After screenshot image

一样的问题,你最后解决了吗

h2c没有解决,最后换方案了,用webrtc解决了

我找到原因了
是这里获取input框字体大小的时候取的数组位置不对,应该取[1,2],但实际取了[0,1]
这就导致所有Input类型的元素都默认12px字体大小给的baseline
https://github.com/niklasvh/html2canvas/blob/master/src/render/canvas/canvas-renderer.ts#L391

回复之后才发现@ohaibbq 已经提交了合并请求,希望这个bug被尽快合并吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants