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
Feat: Export to image #9037
Feat: Export to image #9037
Conversation
/* fixes an html2canvas issue */ | ||
img { | ||
@apply inline-block; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor tweaks to the existing styles might be required to improve the result.
7c016a7
to
b841811
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sprocketc QAed all the exports and they work great! 👍 Left minor comments. When QAing any of the new export functionality it failed on publishing:
I pushed up a fix assuming you want this functionality on publishing but feel free to also disable export on publishing or do something else
@@ -264,6 +264,7 @@ | |||
:-webkit-font-smoothing "subpixel-antialiased"}} | |||
|
|||
[:div.whiteboard-page-title-root | |||
{:data-html2canvas-ignore true} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be useful to document or comment somewhere when to use this option and why. I saw it in the PR but having dev docs in PRs aren't easy to find
…feat/export-to-image
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent PR!
I've QAed all the cases, and they all function perfectly!
I observed a UI inconsistency issue, the PNG
button is missing when selecting multiple blocks and copy/export as.
Only the first selected block will be exported as PNG.
Additionally, the default option for "copy/export as" blocks is now PNG export, which might not align with users' preferences.
Another minor bug is that the generated title when saving a file is not user-friendly.
For pages, the lower-cased page name is used instead of its original name,
for blocks, the title example is [#uuid _64365bd1-e340-4690-ad00-6d898c214f6d_]
,
I suggest using logseq_{page}
for any page and logseq_{timestamp}
for block(s).
I recorded a video on it:
https://www.loom.com/share/8500691f9c924f4fafb0d948d0798bd4
Multi-block export is not supported, but the last selected type was used. I had to reset the type on export to avoid this.
Handled. |
@sprocketc Good to know that multiple blocks exported as PNG is not supported.
Works as described. |
* feat: export to image * chore: export selection on whiteboards * fix: whiteboards zoom on export * fix: loading position * chore: support video thumb * core: add export to whiteboards context menu * fix: context menu entry * fix; copy image to clipboard * fix: copy / export label * fix: hide ui elements * fix: remove random character * fix: graph export * chore: remove console log and jpg format * style: run prettier * fix: disable on multiple selected blocks * fix: multiple blocks * enhance: restrict bounds of selected shapes * chore: export selection on whiteboards * fix: whiteboards zoom on export * chore: support video thumb * core: add export to whiteboards context menu * fix: context menu entry * fix; copy image to clipboard * fix: copy / export label * fix: hide ui elements * fix: remove random character * fix: graph export * chore: remove console log and jpg format * style: run prettier * fix: disable on multiple selected blocks * fix: multiple blocks * enhance: restrict bounds of selected shapes * Fix any html2canvas related functionality failing in publishing * fix: portal header gradient on export * chore: add comment about html2canvas-ignore attr * fix: use export padding constant * fix: export collapsed portals with size > medium * fix: reset export type * enhance: export filename --------- Co-authored-by: Gabriel Horner <gabriel@logseq.com> Co-authored-by: Tienson Qin <tiensonqin@gmail.com>
This PR was originally about whiteboards, but I decided to expand its functionality to blocks and pages. The initial problem was the fact that tldraw converts all shapes to SVGs to export them. In our case, converting portals to svgs would be extremely complicated, so I decided to use html2canvas.
Related to
https://discuss.logseq.com/t/whiteboards-requests/16288
https://discord.com/channels/725182569297215569/1055672588162048110/1055672588162048110
Quoting their docs
So what does this have to offer compared to simply taking a screenshot?
data-html2canvas-ignore
attribute)I used out existing export modal. I also added a "save to file" that should also work for preexisting formats (text, html etc).
We can now export
The whole page will be exported. Lazily loaded elements that are not part of the DOM yet, won't be included.
Only selected shapes will be included. If there are no selected shapes, all of them will be exported. The visible viewport will be used, but the zoom/scale will be corrected upon export. The image bounds will also be restricted to the current selection, when we use the context menu.
Graphs were already rendered to a canvas, so we don't need html2canvas in this case. The reason I added this in this PR, is that exporting images of graphs with transparent background, could be useful to some users.
UI features
The currently supported format is PNG. Supporting JPGs and WEBPs should be trivial. I chose PNG because it has alpha channel support, so we can have a transparent background.
Caveats
Screencast.from.2023-04-07.20-37-23.webm