Current section
Files
Jump to
Current section
Files
lib/vivid/png/shape.ex
defmodule Vivid.PNG.ShapeToPng do alias Vivid.{PNG, Shape, Bounds, Transform, Frame} @moduledoc false @doc false @spec to_png(Shape.t, Path.t) :: :ok | {:error, any} def to_png(shape, file) do bounds = Bounds.bounds(shape) width = bounds |> Bounds.width |> round |> Kernel.+(3) height = bounds |> Bounds.height |> round |> Kernel.+(3) frame = Frame.init(width, height) shape = shape |> Transform.center(frame) |> Transform.apply frame |> Frame.push(shape, RGBA.black) |> PNG.to_png(file) endendEnum.each(~w(Arc Box Circle Group Line Path Polygon), fn mod -> mod = Module.concat(Vivid, mod) defimpl Vivid.PNG, for: mod do def to_png(shape, file), do: Vivid.PNG.ShapeToPng.to_png(shape, file) endend)