{"id":15673460,"url":"https://github.com/lmammino/svg-invert","last_synced_at":"2025-05-06T22:13:47.041Z","repository":{"id":239152120,"uuid":"798700335","full_name":"lmammino/svg-invert","owner":"lmammino","description":"CLI utility and a library to invert colors in an SVG image","archived":false,"fork":false,"pushed_at":"2024-05-12T09:24:02.000Z","size":49,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-06T22:13:38.334Z","etag":null,"topics":["cli","cli-app","cli-tool","color","image","image-processing","rust","svg","vector"],"latest_commit_sha":null,"homepage":"https://loige.co","language":"Rust","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/lmammino.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-05-10T10:01:22.000Z","updated_at":"2025-04-08T03:37:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"ce6b7039-a317-42b3-9818-bef9f046a6b1","html_url":"https://github.com/lmammino/svg-invert","commit_stats":null,"previous_names":["lmammino/svg-invert"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fsvg-invert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fsvg-invert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fsvg-invert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fsvg-invert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lmammino","download_url":"https://codeload.github.com/lmammino/svg-invert/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252776600,"owners_count":21802469,"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":["cli","cli-app","cli-tool","color","image","image-processing","rust","svg","vector"],"created_at":"2024-10-03T15:40:39.683Z","updated_at":"2025-05-06T22:13:46.643Z","avatar_url":"https://github.com/lmammino.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# svg-invert\n\n[![Build Status](https://github.com/lmammino/svg-invert/actions/workflows/rust.yml/badge.svg)](https://github.com/lmammino/svg-invert/actions/workflows/rust.yml)\n[![codecov](https://codecov.io/gh/lmammino/svg-invert/graph/badge.svg?token=2a5OOr6Um4)](https://codecov.io/gh/lmammino/svg-invert)\n[![Crates.io](https://img.shields.io/crates/v/svg-invert.svg)](https://crates.io/crates/svg-invert)\n[![Documentation](https://docs.rs/svg-invert/badge.svg)](https://docs.rs/svg-invert)\n\nA CLI utility that inverts colors in an SVG file.\n\n---\n\n## 💁‍♂️ Use case\n\nIf you ever need to invert all the colors (fill and stroke) in an SVG file, this simple CLI utility is for you.\n\nMy original use case was to be able to invert black and white-ish diagrams so that they can be used in both light and dark mode in an e-book, but I reckon this utility can fulfill many other use cases. [Let me know](https://twitter.com/loige) what you'll use it for! 🚀\n\n\n## 🛠️ Installation\n\nYou can install `svg-invert` using precompiled binaries (if available for your operative system and architecture) or by compiling it from source.\n\n### Using precompiled binaries\n\nYou can download precompiled binaries from the [releases page](https://github.com/lmammino/svg-invert/releases) and place them in a directory that is in your `PATH`.\n\nIf you have [`cargo binstall`](https://github.com/cargo-bins/cargo-binstall) in your system, you can use it to install the latest version of `svg-invert`:\n\n```bash\ncargo binstall svg-invert\n```\n\nThis method has the advantage of automatically placing the binary in a directory that is in your `PATH`. Also, if a binary is not available for your operative system and architecture, `cargo binstall` will compile it for you (assuming you have all the necessary Rust build toolchain in your system).\n\n### Compiling from source\n\nIf you have the Rust toolchain installed in your system, you can compile `svg-invert` from source using `cargo`:\n\n```bash\ncargo install svg-invert\n```\n\n## 👩‍🏫 Usage\n\nRight now, `svg-invert` offers only a very simple and minimal interface: data in from stdin and data out to stdout:\n\n```bash\nsvg-invert \u003c some-lovely.svg \u003e inverted-some-lovely.svg\n```\n\nor, if you like Unix pipes:\n\n```bash\ncat some-lovely.svg | svg-invert \u003e inverted-some-lovely.svg\n```\n\nFor example, if this is the content of `some-lovely.svg`:\n\n![A lovely crab with a Lambda hat](./examples/some-lovely.svg)\n\nAfter running the command, this will be the content of `inverted-some-lovely.svg`:\n\n![A lovely crab with a Lambda hat with inverted colours](./examples/inverted-some-lovely.svg)\n\n\u003e [!NOTE]\n\u003e If think this little crab is cute, you should check out my book [Crafting Lambda Functions in Rust](https://rust-lambda.com) where you can learn how to build serverless applications with Rust and AWS Lambda! 🦀🚀 Fun fact: This utility was actually born as a way to create SVGs diagrams that look good on both the light and dark version of the e-book!\n\n## Usage as a library\n\nYou can use this utility also as part of you own Rust program by using it as a library.\n\nYou can install the library with:\n\n```bash\ncargo add svg-invert\n```\n\nThen you can use it in your Rust program like this:\n\n```rust\nuse std::io::{stdin, stdout, BufReader, BufWriter, Write};\nuse svg_invert::invert_svg;\n\nlet reader = BufReader::new(stdin());\nlet writer = BufWriter::new(stdout());\nmatch invert_svg(reader, writer) {\n  Ok(_) =\u003e {\n    // makes sure to flush stdout before exiting\n    // since we are using a BufWriter\n    match stdout().flush() {\n      Ok(_) =\u003e {}\n      Err(e) =\u003e {\n        eprintln!(\"Error: {e}\");\n      }\n    }\n  }\n  Err(e) =\u003e {\n    eprintln!(\"Error: {e}\");\n  }\n}\n```\n\n## Processing multiple images\n\n[svg_invert::invert_svg](fn.invert_svg.html) is a shortcut for creating a new [InvertSvg](struct.InvertSvg.html) instance and calling its [invert_svg](struct.InvertSvg.html#method.invert_svg) method.\n\nIf you intend to process multiple SVG images in the same program, it might be beneficial to create a single [InvertSvg](struct.InvertSvg.html) instance and reuse it.\n\nIn fact, an [InvertSvg](struct.InvertSvg.html) instance holds an internal cache that stores the inverted colors of the SVG images it processes.\nSo, by reusing the same instance, you might have some performance gains if your images happen to share the same colors.\n\n```rust\nuse svg_invert::InvertSvg;\n\nlet invert_svg = InvertSvg::new();\n// call invert_svg.invert_svg(...) multiple times\n```\n\n## 👷 Contributing\n\nEveryone is very welcome to contribute to this project.\nYou can contribute just by submitting bugs or suggesting improvements by\n[opening an issue on GitHub](https://github.com/lmammino/svg-invert/issues).\n\n\n## 👩‍⚖️ License\n\nLicensed under [MIT License](LICENSE). © Luciano Mammino.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmammino%2Fsvg-invert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flmammino%2Fsvg-invert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmammino%2Fsvg-invert/lists"}