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

第一段的程式碼有誤 附上更正版本 #1

Open
Jeffrey0117 opened this issue Apr 21, 2023 · 1 comment
Open

第一段的程式碼有誤 附上更正版本 #1

Jeffrey0117 opened this issue Apr 21, 2023 · 1 comment

Comments

@Jeffrey0117
Copy link

正確版本

// 抓取指定的 div,產生 base64 格式圖片
// 之所以重複二次,下一段的注意事項會解釋
const el = document.getElementById('xxx');
const config = {
quality: 1,
style: { "filter": "grayscale(100%)" }
};

//原本這裡呼叫config的時候 名字打得跟宣告的地方不同
const dataUriTemp = await domtoimage.toPng(el, config).then(dataUrl => dataUrl);
const dataUri = await domtoimage.toPng(el, config).then(dataUrl => dataUrl);

// 下載圖片
const link = document.createElement('a');
const filename = 'Demo.png';
link.download = filename;
link.href = dataUri;
link.click();

@letswritetw
Copy link
Owner

哦對,沒發現放 Demo Code 的時候寫錯,不過 GitHub 的程式碼是寫對的。
當時製作時必須寫二遍才有圖,剛測試程式碼不變,只寫一次也有圖,神奇。

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

No branches or pull requests

2 participants