diff --git a/README.md b/README.md index 8acd3ab..fdafe2f 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,24 @@ is included in the `LICENSE` file in this distribution. ## Documentation Documentations can be found at [https://hexdocs.pm/vivid_png](https://hexdocs.pm/vivid_png). + +## Status + +```elixir +use Vivid +alias Vivid.PNG + +frame = Frame.init(300,200) +text = Font.line("seems to work") + |> Transform.fill(frame) + |> Transform.center(frame) + |> Transform.apply +circle = Circle.init(Point.init(100, 100), 50) +box = Box.init(Point.init(250,150), Point.init(275, 175)) + +frame +|> Frame.push(text, RGBA.black) +|> Frame.push(circle, RGBA.init(1,0,0,0.5)) +|> Frame.push(box, RGBA.init(0,0,1, 0.75)) +|> PNG.to_png("example.png") +``` \ No newline at end of file diff --git a/example.png b/example.png new file mode 100644 index 0000000..3625ee8 Binary files /dev/null and b/example.png differ diff --git a/lib/vivid/png/buffer.ex b/lib/vivid/png/buffer.ex index c115447..aabcef4 100644 --- a/lib/vivid/png/buffer.ex +++ b/lib/vivid/png/buffer.ex @@ -1,7 +1,14 @@ defimpl Vivid.PNG, for: Vivid.Buffer do - alias Vivid.PNG.Palette alias Vivid.{Buffer, RGBA} + @moduledoc """ + Convert a Vivid buffer to a PNG file. + """ + + @doc """ + Convert a Vivid buffer into a PNG file. + """ + @spec to_png(Buffer.t, Path.t) :: :ok | {:error, any} def to_png(buffer, path) do with {:ok, file} <- File.open(path, [:write]), png <- create_png(buffer, file), diff --git a/lib/vivid/png/frame.ex b/lib/vivid/png/frame.ex index 6fed81d..b1a00b4 100644 --- a/lib/vivid/png/frame.ex +++ b/lib/vivid/png/frame.ex @@ -1,6 +1,14 @@ defimpl Vivid.PNG, for: Vivid.Frame do alias Vivid.{PNG, Frame} + @moduledoc """ + Convert a Vivid frame into a PNG file. + """ + + @doc """ + Convert a Vivid frame into a PNG file. + """ + @spec to_png(Frame.t, Path.t) :: :ok | {:error, any} def to_png(frame, file) do frame |> Frame.buffer(:horizontal) diff --git a/lib/vivid/png/shape.ex b/lib/vivid/png/shape.ex index d1c6296..5be1eed 100644 --- a/lib/vivid/png/shape.ex +++ b/lib/vivid/png/shape.ex @@ -1,7 +1,10 @@ defmodule Vivid.PNG.ShapeToPng do - use Vivid - alias Vivid.PNG + 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) diff --git a/lib/vivid_png.ex b/lib/vivid_png.ex index 20f4445..45fde85 100644 --- a/lib/vivid_png.ex +++ b/lib/vivid_png.ex @@ -1,5 +1,5 @@ defprotocol Vivid.PNG do - alias Vivid.Shape + alias Vivid.{Shape, Frame, Buffer} @moduledoc """ Turn a Vivid frame or shape into a PNG """ @@ -7,6 +7,6 @@ defprotocol Vivid.PNG do @doc """ Turn a frame or shape into a PNG file. """ - @spec to_png(Shape.t, Path.t) :: :ok | {:error, any} + @spec to_png(Shape.t | Frame.t | Buffer.t, Path.t) :: :ok | {:error, any} def to_png(shape, file) end diff --git a/mix.exs b/mix.exs index 69b2ff9..df08fbb 100644 --- a/mix.exs +++ b/mix.exs @@ -12,12 +12,8 @@ defmodule Vivid.PNG.Mixfile do deps: deps()] end - # Configuration for the OTP application - # - # Type "mix help compile.app" for more information def application do - # Specify extra applications you'll use from Erlang/Elixir - [extra_applications: [:logger, :png]] + [applications: [:logger, :png]] end def description do @@ -28,7 +24,7 @@ defmodule Vivid.PNG.Mixfile do def package do [ - maintainers: [ "James Harton " ], + maintainers: [ "James Harton " ], licenses: [ "MIT" ], links: %{ "Source" => "https://github.com/jamesotron/vivid_png.ex" @@ -36,15 +32,6 @@ defmodule Vivid.PNG.Mixfile do ] end - # Dependencies can be Hex packages: - # - # {:my_dep, "~> 0.3.0"} - # - # Or git/path repositories: - # - # {:my_dep, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} - # - # Type "mix help deps" for more examples and options defp deps do [ {:ex_doc, ">= 0.0.0", only: :dev},