Elixir bindings for the OXVG SVG optimizer.
Oxvg.optimize/2 accepts an SVG binary and returns an optimized SVG.
def deps do
[{:oxvg, "~> 0.1.0"}]
end{:ok, optimized_svg} = Oxvg.optimize(svg)preset: is one of :default, :safe, or :none and defaults to
:default. Adding a job never changes the selected preset. Use preset: :none
for a custom-only job set.
# Default preset plus prefixIds.
Oxvg.optimize(svg,
jobs: %{prefix_ids: %{prefix: "icon", delim: "-"}}
)
# Only prefixIds.
Oxvg.optimize(svg,
preset: :none,
jobs: %{prefix_ids: %{prefix: "icon", delim: "-"}}
)Each job can be in one of four states:
- Missing: inherit the preset's state.
:default: enable the job with OXVG's default configuration.:disable: disable the job, including one inherited from a preset.- Any other JSON-compatible value: enable the job with that exact upstream
configuration value. Accepted values are valid UTF-8 binaries, integers in
the supported JSON
i64-minimum throughu64-maximum domain, floats, booleans,nil, proper lists, and maps. Only:defaultand:disableare accepted atoms. Unsupported values return an:invalid_valueconfiguration error.
false is a configuration value, not a disable sentinel. Atom keys
are recursively converted from snake_case to OXVG camelCase. Binary keys are
passed through unchanged so callers can use upstream camelCase job and option
names directly.
optimize/2 returns {:ok, binary} or
{:error, %Oxvg.Error{stage, reason, message, path, value}}.
stageis:config,:parse,:optimize, or:serialize.reasonis a stable atom. Configuration failures use:invalid_source,:invalid_options,:unknown_option,:invalid_preset,:invalid_jobs,:invalid_key,:key_collision, or:invalid_value. Native failures use:invalid_configuration,:invalid_svg,:optimization_failed, or:serialization_failed.messageis a human-readable binary.pathretains the original Elixir keys and zero-based list indexes for configuration errors (or isnilfor native failures).valueis the rejected configuration value when known (or isnilfor native failures).
Oxvg.optimize!/2 returns the optimized SVG on success and raises the returned
Oxvg.Error on failure.
Published packages download precompiled NIFs for:
aarch64-apple-darwin
x86_64-apple-darwin
x86_64-unknown-linux-gnu
aarch64-unknown-linux-gnu
x86_64-unknown-linux-musl
aarch64-unknown-linux-musl
x86_64-pc-windows-msvc
Set OXVG_BUILD=1 to build from source during development or on unsupported
targets:
OXVG_BUILD=1 mix testThis library was developed with help from LLMs.
MIT. See the license text.