{"id":20622795,"url":"https://github.com/wietsewind/svg-rasterizer","last_synced_at":"2026-04-18T08:02:00.282Z","repository":{"id":261380011,"uuid":"884137286","full_name":"WietseWind/svg-rasterizer","owner":"WietseWind","description":"Rasterize SVG images from URL to PNG (Rust)","archived":false,"fork":false,"pushed_at":"2024-11-06T10:25:26.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-09T23:35:56.194Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/WietseWind.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-11-06T08:00:55.000Z","updated_at":"2024-11-06T10:25:29.000Z","dependencies_parsed_at":"2024-11-06T09:18:04.317Z","dependency_job_id":"89b8bcf6-5209-4618-815d-da31ada3c7d5","html_url":"https://github.com/WietseWind/svg-rasterizer","commit_stats":null,"previous_names":["wietsewind/svg-rasterizer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/WietseWind/svg-rasterizer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WietseWind%2Fsvg-rasterizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WietseWind%2Fsvg-rasterizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WietseWind%2Fsvg-rasterizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WietseWind%2Fsvg-rasterizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WietseWind","download_url":"https://codeload.github.com/WietseWind/svg-rasterizer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WietseWind%2Fsvg-rasterizer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31961348,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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-11-16T12:24:42.968Z","updated_at":"2026-04-18T08:02:00.265Z","avatar_url":"https://github.com/WietseWind.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Return rasterized PNG from sanitized and checked SVG URL (Rust)\n\nA secure service that fetches, validates, sanitizes and rasterizes SVG files from URLs. Returns PNGs with configurable dimensions. Features caching, rate limiting and protection against common attack vectors. Written in Rust using actix-web.\n\n## Features\n\n- Fetches SVG from provided URL\n- Validates URLs and prevents local network access\n- Sanitizes SVG using [svg-hush](https://lib.rs/svg-hush)\n- Rasterizes to PNG with configurable dimensions using resvg\n- Redis-based caching (24h for valid SVGs, 60s for errors)\n- Rate limiting (configurable with Cloudflare IP support)\n- Automatic redirect for non-SVG URLs\n- Returns PNG with proper content-type headers\n\n## Requirements\n\n- Rust 1.74+ (2021 edition)\n- Redis server\n- [svg-hush](https://lib.rs/svg-hush) binary installed (`cargo install svg-hush`)\n- Port 3000 access (or configure different port)\n\n## Installation\n\n```bash\n# Install svg-hush (required)\ncargo install svg-hush\n\n# Clone repository\ngit clone https://github.com/WietseWind/svg-rasterizer\ncd svg-rasterizer\n\n# Install dependencies and build\ncargo build --release\n\n# Start debug\nRUST_LOG=svg_rasterizer=debug,actix_web=debug cargo run\n\n# OR: Start service\ncargo run --release\n```\n\n## Configuration\n\nEnvironment variables:\n- `PORT`: Server port (default: 3000)\n- `REDIS_URL`: Redis connection string (default: redis://localhost:6379)\n- `MAX_DIMENSION`: Maximum allowed width/height (default: 4096)\n- `RUST_LOG`: Logging level (default: debug), e.g. debug, info, warn\n\n## Usage\n\n### API Endpoint\n\n```\nGET /rasterize-svg\n```\n\n### Query Parameters\n\n- `url`: (Required) URL of the SVG to process\n- `width`: (Optional) Output width in pixels (32-4096, default: 1024)\n- `height`: (Optional) Output height in pixels (32-4096, default: 1024)\n\n### Examples\n\n```bash\n# Basic usage\ncurl \"http://localhost:3000/rasterize-svg?url=https://example.com/image.svg\"\n\n# Custom dimensions\ncurl \"http://localhost:3000/rasterize-svg?url=https://example.com/image.svg\u0026width=800\u0026height=600\"\n```\n\n### Response Types\n\nThe service automatically detects the client type and responds appropriately:\n\n#### Browser/Image Client\n- Content-Type: image/png\n- Direct PNG image response\n\n#### API Client (curl with non-image Accept header)\n```json\n{\n  \"success\": true,\n  \"format\": \"png\",\n  \"size\": 12345,\n  \"width\": 1024,\n  \"height\": 1024,\n  \"contentType\": \"image/png\",\n  \"data\": \"data:image/png;base64,...\"\n}\n```\n\n### Error Handling\n\n- Non-SVG URLs: 400 Bad Request with error message\n- Invalid URLs: 400 Bad Request with error message\n- Rate limit exceeded: 429 Too Many Requests\n- Server errors: 500 Internal Server Error\n\n## Rate Limiting\n\n- 60 requests per 60 seconds per IP (configurable)\n- Redis-based rate limiting\n- Proper handling of Cloudflare IPs and headers\n\n## Caching\n\n- Successful SVG conversions: 24 hours\n- Errors: 60 seconds\n- Cache key based on URL and requested dimensions\n\n## Running with systemd\n\nCreate a systemd service file `/etc/systemd/system/svg-rasterizer.service`:\n\n```ini\n[Unit]\nDescription=SVG Rasterizer Service\nAfter=network.target\n\n[Service]\nType=simple\nUser=youruser\nWorkingDirectory=/path/to/svg-rasterizer\nEnvironment=RUST_LOG=debug\nEnvironment=PORT=3000\nEnvironment=REDIS_URL=redis://localhost:6379\nExecStart=/path/to/svg-rasterizer/target/release/svg-rasterizer\nRestart=always\n\n[Install]\nWantedBy=multi-user.target\n```\n\nThen:\n```bash\nsudo systemctl enable svg-rasterizer\nsudo systemctl start svg-rasterizer\nsudo systemctl status svg-rasterizer\n```\n\n## Security\n\n- URL validation prevents local network access\n- SVG sanitization removes potentially harmful content (via svg-hush)\n- Rate limiting prevents abuse\n- Maximum file size limits\n- Timeouts on all external requests (10s)\n- Memory limits on PNG generation\n- Safe SVG to PNG conversion using resvg\n\n## Development\n\n```bash\n# Run with debug logging\nRUST_LOG=debug cargo run\n\n# Run tests\ncargo test\n\n# Check formatting\ncargo fmt -- --check\n\n# Run linter\ncargo clippy\n```\n\n## License\n\nMIT\n\n## Contributing\n\nPRs welcome! Please ensure you follow the existing code style and add tests for any new features.\n\n## Performance\n\nThe Rust implementation offers several advantages over the Node.js version:\n- Lower memory usage\n- Better CPU utilization\n- Faster processing times\n- More predictable performance under load\n- Native binary without runtime dependencies","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwietsewind%2Fsvg-rasterizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwietsewind%2Fsvg-rasterizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwietsewind%2Fsvg-rasterizer/lists"}