Skip to content

Commit 7e7b78d

Browse files
committedNov 24, 2024·
Add png component
1 parent 3128671 commit 7e7b78d

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed
 

‎apps/web/app/landing/download.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use client"
2+
import * as htmlToImage from "html-to-image"
3+
4+
export function Download({ selector }: { selector: string }) {
5+
const onClick = async () => {
6+
const nodes = document.querySelectorAll(selector) as any
7+
for (const node of nodes) {
8+
const dataUrl = await htmlToImage.toPng(node as HTMLElement)
9+
var img = new Image()
10+
img.src = dataUrl
11+
document.getElementById("out")!.appendChild(img)
12+
}
13+
}
14+
return (
15+
<div>
16+
<button onClick={onClick}>As PNG</button>
17+
<div id="out" className="min-w-6 min-h-6 border"></div>
18+
</div>
19+
)
20+
}

‎apps/web/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"diff": "^5.1.0",
2727
"dotenv": "^16.4.1",
2828
"estree-util-to-js": "^2.0.0",
29+
"html-to-image": "^1.11.11",
2930
"lucide-react": "^0.303.0",
3031
"next": "14.1.0",
3132
"next-docs-mdx": "7.1.2",

‎pnpm-lock.yaml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.