{"id":18016648,"url":"https://github.com/bioforestchain/svg-wasm","last_synced_at":"2025-03-26T18:32:26.652Z","repository":{"id":256726105,"uuid":"855693371","full_name":"BioforestChain/svg-wasm","owner":"BioforestChain","description":"SVG Wasm toolkit","archived":false,"fork":false,"pushed_at":"2024-09-23T16:23:47.000Z","size":1802,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T07:22:55.349Z","etag":null,"topics":["png","svg","wasm","webp"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BioforestChain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-11T09:58:49.000Z","updated_at":"2024-10-14T03:29:38.000Z","dependencies_parsed_at":"2024-09-14T03:34:02.868Z","dependency_job_id":null,"html_url":"https://github.com/BioforestChain/svg-wasm","commit_stats":null,"previous_names":["bioforestchain/svg-wasm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BioforestChain%2Fsvg-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BioforestChain%2Fsvg-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BioforestChain%2Fsvg-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BioforestChain%2Fsvg-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BioforestChain","download_url":"https://codeload.github.com/BioforestChain/svg-wasm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245713105,"owners_count":20660344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["png","svg","wasm","webp"],"created_at":"2024-10-30T04:18:45.293Z","updated_at":"2025-03-26T18:32:26.271Z","avatar_url":"https://github.com/BioforestChain.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# svg-wasm\n\nSVG Wasm toolkit, including `svg_to_png` and `svg_to_webp`,`detect_svg_render`, capable of detecting if an SVG causes a memory overflow.\n\n## example\n\nHow to use the sample project that can be viewed, you can use this project on any platform without worrying about copyright issues.\n\n### `detect_svg_render`\n\nCheck whether the SVG is overflowing。\n\n```ts\nconsole.log(\"detect_svg_render=\u003e\", detect_svg_render(svg, 2));\n```\n\n### `svg_to_webp`\n\n```ts\nconst svg = fs.readFileSync(\"../test.svg\");\nconst webp_data = svg_to_webp(svg);\nfs.writeFileSync(\"./test.webp\", webp_data);\n```\n\n### `svg_to_png`\n\nThe third parameter is that the fill type contains `Fill` and `Contain`.\n\n- `Contain`: Equal proportional enlargement will not cause the image to be distorted.\n- `Fill`:With filling, the image may be distorted.\n\n```ts\nconst svg = fs.readFileSync(\"../test.svg\");\nconst webp_data = svg_to_png(svg, 996.0, 500.0, \"Contain\", 5242880.0);\nfs.writeFileSync(\"./test.png\", webp_data);\n```\n\n## import wasm\n\n### how to use within vite\n\nfetch wasm file\n\nVite will automatically pack the wasm file into the dist/assets folder. On the website, it will download this wasm file using network.\n\n```ts\nimport init from \"@dweb-browser/svg-wasm\";\nimport svg_wasm_url from \"@dweb-browser/svg-wasm/svg_wasm_bg.wasm?url\";\nimport { test_svg_to_webp } from \"./index.ts\";\ninit(svg_wasm_url).then(() =\u003e {\n  test_svg_to_webp(\"fetch test\");\n});\n\n```\n\nbundle wasm into js with base64 encoding\n\n```ts\nimport { initSync } from \"@dweb-browser/svg-wasm\";\nimport get_svg_wasm_binary from \"@dweb-browser/svg-wasm/svg_wasm_bg_wasm\";\ninitSync(get_svg_wasm_binary());\n```\n\n\n## how  to use within node\n\n### commonjs\n\n```js\nconst { svg_to_webp } = require(\"@dweb-browser/svg-wasm\");\n```\n\n### esmodule\n\n```mjs\nimport { detect_svg_render, initSync, svg_to_webp } from \"@dweb-browser/svg-wasm\";\nimport fs from \"node:fs\";\nimport url from \"node:url\";\nconst svg_wasm_binary = fs.readFileSync(\n  url.fileURLToPath(\n    import.meta.resolve(\"@dweb-browser/svg-wasm/svg_wasm_bg.wasm\"),\n  ),\n);\ninitSync({ module: svg_wasm_binary })\n```\n \n## how to build\n\n1. rustup target add wasm32-unknown-unknown\n1. install [wasm-bindgen]() `cargo install wasm-bindgen-cli`\n1. install [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/)\n   `cargo install wasm-pack`\n1. install [tsc](http://npmjs.com/package/typescript) `npm install -g typescript`\n1. install [deno](https://deno.com/)\n   ```\n   curl -fsSL https://deno.land/install.sh | sh # macos or linux\n   irm https://deno.land/install.ps1 | iex # windows\n   ```\n1. run script: `deno task build`\n   \u003e output to [pkg](./pkg) folder\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbioforestchain%2Fsvg-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbioforestchain%2Fsvg-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbioforestchain%2Fsvg-wasm/lists"}