{"id":13445613,"url":"https://github.com/chuyun/taro-plugin-canvas","last_synced_at":"2026-01-27T05:38:22.260Z","repository":{"id":34297099,"uuid":"175194512","full_name":"chuyun/taro-plugin-canvas","owner":"chuyun","description":"基于 Taro 框架的微信小程序 canvas 绘图组件，封装了常用的操作，通过配置的方式生成分享图片","archived":false,"fork":false,"pushed_at":"2022-12-10T16:57:47.000Z","size":4878,"stargazers_count":505,"open_issues_count":41,"forks_count":63,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-08-31T05:44:06.990Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chuyun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-12T11:13:24.000Z","updated_at":"2024-08-31T00:27:00.000Z","dependencies_parsed_at":"2023-01-15T06:15:37.729Z","dependency_job_id":null,"html_url":"https://github.com/chuyun/taro-plugin-canvas","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/chuyun/taro-plugin-canvas","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chuyun%2Ftaro-plugin-canvas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chuyun%2Ftaro-plugin-canvas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chuyun%2Ftaro-plugin-canvas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chuyun%2Ftaro-plugin-canvas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chuyun","download_url":"https://codeload.github.com/chuyun/taro-plugin-canvas/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chuyun%2Ftaro-plugin-canvas/sbom","scorecard":{"id":282276,"data":{"date":"2025-08-11","repo":{"name":"github.com/chuyun/taro-plugin-canvas","commit":"48bd8f20cc86d497fbe0f068676fbe3799323498"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.9,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":1,"reason":"Found 3/23 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 11 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"118 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-6chw-6frg-f759","Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-whgm-jr23-g3j9","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25","Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx","Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw","Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-3wcq-x3mq-6r9p","Warn: Project is vulnerable to: GHSA-ff7x-qrg7-qggm","Warn: Project is vulnerable to: GHSA-vh7m-p724-62c2","Warn: Project is vulnerable to: GHSA-r9p9-mrjm-926w","Warn: Project is vulnerable to: GHSA-434g-2637-qmqr","Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m","Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw","Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p","Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747","Warn: Project is vulnerable to: GHSA-vjh7-7g9h-fjfh","Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h","Warn: Project is vulnerable to: GHSA-6h5x-7c5m-7cr7","Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc","Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx","Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q","Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c","Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc","Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3","Warn: Project is vulnerable to: MAL-2023-462","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-pfq8-rq6v-vf5m","Warn: Project is vulnerable to: GHSA-6x33-pw7p-hmpq","Warn: Project is vulnerable to: GHSA-c7qv-q95q-8v27","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22","Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp","Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq","Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488","Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-92xj-mqp7-vmcj","Warn: Project is vulnerable to: GHSA-wxgw-qj99-44c2","Warn: Project is vulnerable to: GHSA-5rrq-pxf6-6jx5","Warn: Project is vulnerable to: GHSA-8fr3-hfg3-gpgp","Warn: Project is vulnerable to: GHSA-gf8q-jrpm-jvxq","Warn: Project is vulnerable to: GHSA-2r2c-g63r-vccr","Warn: Project is vulnerable to: GHSA-cfm4-qjh2-4765","Warn: Project is vulnerable to: GHSA-x4jg-mjrx-434g","Warn: Project is vulnerable to: GHSA-9v62-24cr-58cx","Warn: Project is vulnerable to: GHSA-r8f7-9pfq-mjmv","Warn: Project is vulnerable to: GHSA-rp65-9cf3-cjxr","Warn: Project is vulnerable to: GHSA-cwx2-736x-mf6w","Warn: Project is vulnerable to: GHSA-v39p-96qg-c8rf","Warn: Project is vulnerable to: GHSA-8v63-cqqc-6r2c","Warn: Project is vulnerable to: GHSA-76c9-3jph-rj3q","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w","Warn: Project is vulnerable to: GHSA-h7cp-r72f-jxh6","Warn: Project is vulnerable to: GHSA-v62p-rq8g-8h59","Warn: Project is vulnerable to: GHSA-566m-qj78-rww5","Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j","Warn: Project is vulnerable to: GHSA-hwj9-h5mp-3pm3","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-7mwh-4pqv-wmr8","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg","Warn: Project is vulnerable to: GHSA-h9rv-jmmf-4pgx","Warn: Project is vulnerable to: GHSA-hxcc-f52p-wc94","Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p","Warn: Project is vulnerable to: GHSA-c9g6-9335-x697","Warn: Project is vulnerable to: GHSA-vx3p-948g-6vhq","Warn: Project is vulnerable to: GHSA-p3hc-fv2j-rp68","Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9","Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw","Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc","Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p","Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-w5p7-h5w8-2hfq","Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v","Warn: Project is vulnerable to: GHSA-9m6j-fcg5-2442","Warn: Project is vulnerable to: GHSA-hh27-ffr2-f2jc","Warn: Project is vulnerable to: GHSA-rqff-837h-mm52","Warn: Project is vulnerable to: GHSA-8v38-pw62-9cw2","Warn: Project is vulnerable to: GHSA-hgjh-723h-mx2j","Warn: Project is vulnerable to: GHSA-jf5r-8hm2-f872","Warn: Project is vulnerable to: GHSA-wr3j-pwj9-hqq6","Warn: Project is vulnerable to: GHSA-4v9v-hfq4-rm2v","Warn: Project is vulnerable to: GHSA-9jgg-88mc-972h","Warn: Project is vulnerable to: GHSA-g78m-2chm-r7qv","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh","Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp","Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-17T16:12:34.958Z","repository_id":34297099,"created_at":"2025-08-17T16:12:34.963Z","updated_at":"2025-08-17T16:12:34.963Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28804369,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T03:44:14.111Z","status":"ssl_error","status_checked_at":"2026-01-27T03:43:33.507Z","response_time":168,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T05:00:36.543Z","updated_at":"2026-01-27T05:38:22.243Z","avatar_url":"https://github.com/chuyun.png","language":"TypeScript","funding_links":[],"categories":["Libraries","第三方库和组件","TypeScript"],"sub_categories":["Canvas draw","Taro1"],"readme":"# taro-plugin-canvas\n小程序组件-小程序海报组件\n   [![npm](https://img.shields.io/npm/v/taro-plugin-canvas.svg?style=flat \"npm\")](https://www.npmjs.com/package/taro-plugin-canvas)[![npm](https://img.shields.io/npm/dm/taro-plugin-canvas.svg?style=flat \"npm\")](https://www.npmjs.com/package/taro-plugin-canvas)\n\n## 概述\ntaro-plugin-canvas 是基于 Taro 框架的微信小程序 canvas 绘图组件，封装了常用的操作，通过配置的方式生成分享图片\n\n本组件是基于 [wxa-plugin-canvas](https://github.com/jasondu/wxa-plugin-canvas) 的Taro封装版本\n\n## 生成效果\n\u003cimg width=\"300\" src=\"https://github.com/chuyun/taro-plugin-canvas/blob/v1/src/assets/images/demo1.png\"\u003e\u003c/img\u003e \u003cimg width=\"300\" src=\"https://github.com/chuyun/taro-plugin-canvas/blob/v1/src/assets/images/demo2.png\"\u003e\u003c/img\u003e\u003cimg width=\"300\" src=\"https://github.com/chuyun/taro-plugin-canvas/blob/v1/src/assets/images/demo3.png\"\u003e\u003c/img\u003e\n\n## 组件原理说明\n参见 wxa-plugin-canvas =\u003e https://juejin.im/post/5b7e48566fb9a01a1059543f\n\n## 使用之前\n\n使用 taro-plugin-canvas 前，请确保你已经学习过微信官方的 [小程序简易教程](https://mp.weixin.qq.com/debug/wxadoc/dev/) 和 [自定义组件介绍](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/)。\n\n## 安装\n\n#### 通过 npm 安装 (推荐)\n\n小程序已经支持使用 npm 安装第三方包，详见 [npm 支持](https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html?search-key=npm)\n\n``` bash\n# npm\nnpm i taro-plugin-canvas -S --production\n\n# yarn\nyarn add taro-plugin-canvas --production\n```\n## 使用组件\n\n```javascript\n// 引入代码\nimport { TaroCanvasDrawer } from '../../component/taro-plugin-canvas';\n\n// 在 render 方法中调用\n\u003cTaroCanvasDrawer\n  config={this.state.config}\n  onCreateSuccess={this.onCreateSuccess}\n  onCreateFail={this.onCreateFail}\n/\u003e\n// 注意点 \n// config 绘图配置信息 - 必填项\n// onCreateSuccess 绘图成功回调 - 必须实现 =\u003e 接收绘制结果、重置 TaroCanvasDrawer 状态\n// onCreateFail 绘图失败回调 - 必须实现 =\u003e 接收绘制错误信息、重置 TaroCanvasDrawer 状态\n```\n\n\n#### 方式二.下载代码\n\n直接通过 git 下载 taro-plugin-canvas 源代码，并将`src/component/taro-plugin-canvas`目录拷贝到自己的项目的 `src/component`目录中\n\n## 使用组件\n\n```javascript\n// 引入代码 *引入方式和上面的方式一略有不同\nimport TaroCanvasDrawer from '../../component/taro-plugin-canvas';\n\n// 在 render 方法中调用 和方式一一样\n```\n\n\n## 使用注意事项\n\n1. 图片的域名**务必**添加到downloadFile合法域名中（开发设置-服务器域名-downloadFile合法域名）\n【P.s 开发时可 选中不校验合法域名、web-view（业务域名）、TLS 版本以及 HTTPS 证书】\n【P.s 真机运行，可打开调试模式】\n\n## 组件参数解释\n\n### config字段\n\n| 字段            | 类型                     | 必填 | 描述                                       |\n| --------------- | ------------------------ | ---- | ------------------------------------------ |\n| width           | Number(单位:rpx)         | 是   | 画布宽度                                   |\n| height          | Number(单位:rpx)         | 是   | 画布高度                                   |\n| backgroundColor | String                   | 否   | 画布颜色                                   |\n| debug           | Boolean                  | 否   | false隐藏canvas，true显示canvas，默认false |\n| preload         | Boolean                  | 否   | true：图片资源预下载 默认false             |\n| hide-loading    | Boolean                  | 否   | true：隐藏loading 默认false                |\n| blocks          | Object Array（对象数组） | 否   | 看下文                                     |\n| texts           | Object Array（对象数组） | 否   | 看下文                                     |\n| images          | Object Array（对象数组） | 否   | 看下文                                     |\n| lines           | Object Array（对象数组） | 否   | 看下文   |\n| pixelRatio | Number | 否 | 1为一般，值越大越清晰 |\n\n### blocks字段\n\n| 字段名          | 类型             | 必填 | 描述                                   |\n| --------------- | ---------------- | ---- | -------------------------------------- |\n| x               | Number(单位:rpx) | 是   | 块的坐标                               |\n| y               | Number(单位:rpx) | 是   | 块的坐标                               |\n| width           | Number(单位:rpx) | 否   | 如果内部有文字，由文字宽度和内边距决定 |\n| height          | Number(单位:rpx) | 是   |                                        |\n| paddingLeft     | Number(单位:rpx) | 否   | 内左边距                               |\n| paddingRight    | Number(单位:rpx) | 否   | 内右边距                               |\n| borderWidth     | Number(单位:rpx) | 否   | 边框宽度                               |\n| borderColor     | String           | 否   | 边框颜色                               |\n| backgroundColor | String           | 否   | 背景颜色                               |\n| borderRadius    | Number(单位:rpx) | 否   | 圆角                                   |\n| text            | Object           | 否   | 块里面可以填充文字，参考texts字段解释  |\n| zIndex          | Int              | 否   | 层级，越大越高                         |\n\n### texts字段\n\n| 字段名         | 类型             | 必填 | 描述                                                         |\n| -------------- | ---------------- | ---- | ------------------------------------------------------------ |\n| x              | Number(单位:rpx) | 是   | 坐标                                                         |\n| y              | Number(单位:rpx) | 是   | 坐标                                                         |\n| text           | String\\|Object   | 是   | 当Object类型时，参数为text字段的参数，marginLeft、marginRight这两个字段可用（示例请看下文） |\n| fontSize       | Number(单位:rpx) | 是   | 文字大小                                                     |\n| color          | String           | 否   | 颜色                                                         |\n| opacity        | Int              | 否   | 1为不透明，0为透明                                           |\n| lineHeight     | Number(单位:rpx) | 否   | 行高                                                         |\n| lineNum        | Int              | 否   | 根据宽度换行，最多的行数                                     |\n| width          | Number(单位:rpx) | 否   | 没有指定为画布宽度                                           |\n| marginLeft     | Number(单位:rpx) | 否   | 当text字段为Object可以使用，用来控制多行文字间距             |\n| marginRight    | Number(单位:rpx) | 否   | 当text字段为Object可以使用，用来控制多行文字间距             |\n| textDecoration | String           | 否   | 目前只支持 line-through（贯穿线），默认为none                |\n| baseLine       | String           | 否   | top\\| middle\\|bottom基线对齐方式                             |\n| textAlign      | String           | 否   | left\\|center\\|right对齐方式                                  |\n| zIndex         | Int              | 否   | 层级，越大越高                                               |\n| fontFamily     | String           | 否   | 小程序默认字体为'sans-serif', 请输入小程序支持的字体，例如：'STSong' |\n| fontWeight     | String           | 否   | 'bold'加粗字体，目前小程序不支持 100 - 900 加粗            |\n| fontStyle      | String           | 否   | 'italic'倾斜字体                                          |\n\n### images字段\n\n| 字段         | 类型             | 必填 | 描述                                      |\n| ------------ | ---------------- | ---- | ----------------------------------------- |\n| x            | Number(单位:rpx) | 是   | 右上角的坐标                              |\n| y            | Number(单位:rpx) | 是   | 右上角的坐标                              |\n| url          | String           | 是   | 图片url（**需要添加到下载白名单域名中**）也支持本地图片 |\n| width        | Number(单位:rpx) | 是   | 宽度（**会根据图片的尺寸同比例缩放**）    |\n| height       | Number(单位:rpx) | 是   | 高度（**会根据图片的尺寸同比例缩放**）    |\n| borderRadius | Number(单位:rpx) | 否   | 圆角，跟css一样                           |\n| borderWidth  | Number(单位:rpx) | 否   | 边框宽度                                  |\n| borderColor  | String           | 否   | 边框颜色                                  |\n| zIndex       | Int              | 否   | 层级，越大越高                            |\n\n### lines字段\n\n| 字段   | 类型             | 必填 | 描述           |\n| ------ | ---------------- | ---- | -------------- |\n| startX | Number(单位:rpx) | 是   | 起始坐标       |\n| startY | Number(单位:rpx) | 是   | 起始坐标       |\n| endX   | Number(单位:rpx) | 是   | 终结坐标       |\n| endY   | Number(单位:rpx) | 是   | 终结坐标       |\n| width  | Number(单位:rpx) | 是   | 线的宽度       |\n| color  | String           | 否   | 线的颜色       |\n| zIndex | Int              | 否   | 层级，越大越高 |\n\n## 事件\n\n### success\n\n成功回调 onCreateSuccess  \n\n返回生成海报图片的本地url，一般做法是使用wx.previewImage预览海报或者在指定位置预览，如下\n\n```javascript\n// 绘制成功回调函数 （必须实现）=\u003e 接收绘制结果、重置 TaroCanvasDrawer 状态\n  onCreateSuccess = (result) =\u003e {\n    const { tempFilePath, errMsg } = result;\n    Taro.hideLoading();\n    if (errMsg === 'canvasToTempFilePath:ok') {\n      this.setState({\n        shareImage: tempFilePath,\n        // 重置 TaroCanvasDrawer 状态\n        canvasStatus: false,\n        config: null\n      })\n    } else {\n      // 重置 TaroCanvasDrawer 状态\n      this.setState({\n        canvasStatus: false,\n        config: null\n      })\n      Taro.showToast({ icon: 'none', title: errMsg || '出现错误' });\n      console.log(errMsg);\n    }\n  }\n\n```\n\n### fail\n\n错误回调 onCreateFail\n\n```javascript\n// 绘制失败回调函数 （必须实现）=\u003e 接收绘制错误信息、重置 TaroCanvasDrawer 状态\n  onCreateFail = (error) =\u003e {\n    Taro.hideLoading();\n    // 重置 TaroCanvasDrawer 状态\n    this.setState({\n      canvasStatus: false,\n      config: null\n    })\n    console.log(error);\n  }\n```\n\n### Demo \n\n以下是简易的Demo实现，也可以clone代码，里面有具体实现，线上案例见小程序 RssFeed  \n\n\n\u003cdetails\u003e\u003csummary\u003e例子代码（点击展开）\u003c/summary\u003e\u003cbr\u003e\n\n```jsx\nimport Taro, { Component } from '@tarojs/taro'\nimport { View, Button, Image } from '@tarojs/components'\nimport TaroCanvasDrawer from '../../component/taro-plugin-canvas'; // 拷贝文件到component的引入方式\n// import { TaroCanvasDrawer  } from 'taro-plugin-canvas'; // npm 引入方式\nimport './index.scss'\n\nexport default class Simple extends Component {\n  config = {\n    navigationBarTitleText: '首页'\n  }\n  constructor(props) {\n    super(props);\n    this.state = {\n      // 绘图配置文件\n      config: null,\n      // 绘制的图片\n      shareImage: null,\n      // TaroCanvasDrawer 组件状态\n      canvasStatus: false,\n      rssConfig: {\n        width: 750,\n        height: 750,\n        backgroundColor: '#fff',\n        debug: false,\n        blocks: [\n          {\n            x: 0,\n            y: 0,\n            width: 750,\n            height: 750,\n            paddingLeft: 0,\n            paddingRight: 0,\n            borderWidth: 0,\n            // borderColor: '#ccc',\n            backgroundColor: '#EFF3F5',\n            borderRadius: 0,\n          },\n          {\n            x: 40,\n            y: 40,\n            width: 670,\n            height: 670,\n            paddingLeft: 0,\n            paddingRight: 0,\n            borderWidth: 0,\n            // borderColor: '#ccc',\n            backgroundColor: '#fff',\n            borderRadius: 12,\n          }\n        ],\n        texts: [\n          {\n            x: 80,\n            y: 420,\n            text: '国产谍战 真人演出,《隐形守护者》凭什么成为Steam第一?',\n            fontSize: 32,\n            color: '#000',\n            opacity: 1,\n            baseLine: 'middle',\n            lineHeight: 48,\n            lineNum: 2,\n            textAlign: 'left',\n            width: 580,\n            zIndex: 999,\n          },\n          {\n            x: 80,\n            y: 590,\n            text: '长按扫描二维码阅读完整内容',\n            fontSize: 24,\n            color: '#666',\n            opacity: 1,\n            baseLine: 'middle',\n            textAlign: 'left',\n            lineHeight: 36,\n            lineNum: 1,\n            zIndex: 999,\n          },\n          {\n            x: 80,\n            y: 640,\n            text: '分享来自 「 RssFeed 」',\n            fontSize: 24,\n            color: '#666',\n            opacity: 1,\n            baseLine: 'middle',\n            textAlign: 'left',\n            lineHeight: 36,\n            lineNum: 1,\n            zIndex: 999,\n          }\n        ],\n        images: [\n          {\n            url: 'http://pic.juncao.cc/rssfeed/images/demo.png',\n            width: 670,\n            height: 320,\n            y: 40,\n            x: 40,\n            borderRadius: 12,\n            zIndex: 10,\n            // borderRadius: 150,\n            // borderWidth: 10,\n            // borderColor: 'red',\n          },\n          {\n            url: 'https://pic.juncao.cc/cms/images/minapp.jpg',\n            width: 110,\n            height: 110,\n            y: 570,\n            x: 560,\n            borderRadius: 100,\n            borderWidth: 0,\n            zIndex: 10,\n          },\n        ],\n        lines: [\n          {\n            startY: 540,\n            startX: 80,\n            endX: 670,\n            endY: 541,\n            width: 1,\n            color: '#eee',\n          }\n        ]\n      },\n    }\n  }\n\n  // 调用绘画 =\u003e canvasStatus 置为true、同时设置config\n  canvasDrawFunc = (config = this.state.rssConfig) =\u003e {\n    this.setState({\n      canvasStatus: true,\n      config: config,\n    })\n    Taro.showLoading({\n      title: '绘制中...'\n    })\n  }\n\n  // 绘制成功回调函数 （必须实现）=\u003e 接收绘制结果、重置 TaroCanvasDrawer 状态\n  onCreateSuccess = (result) =\u003e {\n    const { tempFilePath, errMsg } = result;\n    Taro.hideLoading();\n    if (errMsg === 'canvasToTempFilePath:ok') {\n      this.setState({\n        shareImage: tempFilePath,\n        // 重置 TaroCanvasDrawer 状态，方便下一次调用\n        canvasStatus: false,\n        config: null\n      })\n    } else {\n      // 重置 TaroCanvasDrawer 状态，方便下一次调用\n      this.setState({\n        canvasStatus: false,\n        config: null\n      })\n      Taro.showToast({ icon: 'none', title: errMsg || '出现错误' });\n      console.log(errMsg);\n    }\n    // 预览\n    // Taro.previewImage({\n    //   current: tempFilePath,\n    //   urls: [tempFilePath]\n    // })\n  }\n\n  // 绘制失败回调函数 （必须实现）=\u003e 接收绘制错误信息、重置 TaroCanvasDrawer 状态\n  onCreateFail = (error) =\u003e {\n    Taro.hideLoading();\n    // 重置 TaroCanvasDrawer 状态，方便下一次调用\n    this.setState({\n      canvasStatus: false,\n      config: null\n    })\n    console.log(error);\n  }\n\n   // 保存图片至本地\n  saveToAlbum = () =\u003e {\n    const res = Taro.saveImageToPhotosAlbum({\n      filePath: this.state.shareImage,\n    });\n    if (res.errMsg === 'saveImageToPhotosAlbum:ok') {\n      Taro.showToast({\n        title: '保存图片成功',\n        icon: 'success',\n        duration: 2000,\n      });\n    }\n  }\n\n  render() {\n    return (\n      \u003cView className='index'\u003e\n        \u003cView\u003e\n          \u003cView className='flex-row'\u003e\n            \u003cButton onClick={this.canvasDrawFunc.bind(this, this.state.rssConfig)}\u003e绘制\u003c/Button\u003e\n            \u003cButton onClick={this.saveToAlbum}\u003e保存到相册\u003c/Button\u003e\n          \u003c/View\u003e\n        \u003c/View\u003e\n        \u003cView className='shareImage-cont'\u003e\n          \u003cImage\n            className='shareImage'\n            src={this.state.shareImage}\n            mode='widthFix'\n            lazy-load\n          /\u003e\n          {\n            // 由于部分限制，目前组件通过状态的方式来动态加载\n            this.state.canvasStatus \u0026\u0026\n            (\u003cTaroCanvasDrawer\n              config={this.state.config} // 绘制配置\n              onCreateSuccess={this.onCreateSuccess} // 绘制成功回调\n              onCreateFail={this.onCreateFail} // 绘制失败回调\n            /\u003e\n            )\n          }\n        \u003c/View\u003e\n      \u003c/View\u003e\n    )\n  }\n}\n\n```\n\n## 问题反馈\n\n有什么问题可以直接提issue\n\n[提issue](https://github.com/chuyun/taro-plugin-canvas/issues/new)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchuyun%2Ftaro-plugin-canvas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchuyun%2Ftaro-plugin-canvas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchuyun%2Ftaro-plugin-canvas/lists"}