├── test ├── test_helper.exs └── mogrify_draw_test.exs ├── lib ├── mogrify_draw.ex └── mogrify │ └── draw.ex ├── mix.lock ├── .gitignore ├── README.md ├── mix.exs ├── LICENSE.md └── config └── config.exs /test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /lib/mogrify_draw.ex: -------------------------------------------------------------------------------- 1 | defmodule MogrifyDraw do 2 | @moduledoc false 3 | end 4 | -------------------------------------------------------------------------------- /test/mogrify_draw_test.exs: -------------------------------------------------------------------------------- 1 | defmodule MogrifyDrawTest do 2 | use ExUnit.Case 3 | doctest MogrifyDraw 4 | 5 | test "the truth" do 6 | assert 1 + 1 == 2 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /mix.lock: -------------------------------------------------------------------------------- 1 | %{"earmark": {:hex, :earmark, "1.0.2", "a0b0904d74ecc14da8bd2e6e0248e1a409a2bc91aade75fcf428125603de3853", [:mix], []}, 2 | "ex_doc": {:hex, :ex_doc, "0.14.2", "c89d60db464e8a0849a35dbcd6eed71f2b076c339d0b05b3bb5c90d6bab31e4f", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]}, 3 | "mogrify": {:hex, :mogrify, "0.5.4", "acb5568335069c5742df444559961b86c304d7969853e77d6561ca916910f75e", [:mix], []}} 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # If the VM crashes, it generates a dump, let's ignore it too. 14 | erl_crash.dump 15 | 16 | # Also ignore archive artifacts (built via "mix archive.build"). 17 | *.ez 18 | -------------------------------------------------------------------------------- /lib/mogrify/draw.ex: -------------------------------------------------------------------------------- 1 | defmodule Mogrify.Draw do 2 | @moduledoc """ 3 | Functions for interacting with the draw functionality from imagemagick 4 | """ 5 | import Mogrify 6 | 7 | def circle(image, originX, originY, perimX, perimY) do 8 | image 9 | |> custom("draw", "circle #{to_string(:io_lib.format("~g,~g ~g,~g", [originX/1, originY/1, perimX/1, perimY/1]))}") 10 | end 11 | 12 | def text(image, x, y, text) do 13 | image 14 | |> custom("draw", "text #{x},#{y} '#{text}'") 15 | end 16 | 17 | def rectangle(image, upper_left_x, upper_left_y, lower_right_x, lower_right_y) do 18 | image 19 | |> custom("draw", "rectangle #{to_string(:io_lib.format("~g,~g ~g,~g", [upper_left_x/1, upper_left_y/1, lower_right_x/1, lower_right_y/1]))}") 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mogrify Draw 2 | 3 | A wrapper of the imagemagick draw functionality on top of mogrify 4 | 5 | ## Installation 6 | 7 | Add this to your `mix.exs` file, then run `mix do deps.get, deps.compile`: 8 | 9 | ```elixir 10 | def deps do 11 | [{:mogrify_draw, "~> 0.1.0"}] 12 | end 13 | ``` 14 | 15 | ```elixir 16 | def application do 17 | [applications: [:mogrify_draw]] 18 | end 19 | ``` 20 | 21 | ## Examples 22 | 23 | 24 | ```elixir 25 | import Mogrify 26 | 27 | %Mogrify.Image{path: "test.png", ext: "png"} 28 | |> custom("size", "280x280") 29 | |> canvas("white") 30 | |> custom("fill", "blue") 31 | |> Mogrify.Draw.circle(140,140,100,100) 32 | |> custom("fill", "yellow") 33 | |> Mogrify.Draw.circle(140,140,140,100) 34 | |> create(path: ".") 35 | ``` 36 | 37 | ## License 38 | 39 | Mogrify Draw source code is licensed under the [MIT License](LICENSE.md). 40 | -------------------------------------------------------------------------------- /mix.exs: -------------------------------------------------------------------------------- 1 | defmodule MogrifyDraw.Mixfile do 2 | use Mix.Project 3 | 4 | def project do 5 | [app: :mogrify_draw, 6 | version: "0.1.1", 7 | elixir: "~> 1.3", 8 | build_embedded: Mix.env == :prod, 9 | start_permanent: Mix.env == :prod, 10 | description: description(), 11 | package: package(), 12 | deps: deps()] 13 | end 14 | 15 | def application do 16 | [applications: [:logger]] 17 | end 18 | 19 | defp deps do 20 | [ 21 | {:mogrify, "~> 0.5.4"}, 22 | {:ex_doc, ">= 0.0.0", only: :dev}, 23 | ] 24 | end 25 | 26 | defp description do 27 | "A wrapper of the imagemagick draw functionality on top of mogrify" 28 | end 29 | 30 | defp package do 31 | [ 32 | files: ["lib", "mix.exs", "README*", "LICENSE*"], 33 | maintainers: ["Luís Zamith"], 34 | licenses: ["MIT"], 35 | links: %{"GitHub" => "https://github.com/zamith/mogrify_draw"} 36 | ] 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2016 Luís Ferreira 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /config/config.exs: -------------------------------------------------------------------------------- 1 | # This file is responsible for configuring your application 2 | # and its dependencies with the aid of the Mix.Config module. 3 | use Mix.Config 4 | 5 | # This configuration is loaded before any dependency and is restricted 6 | # to this project. If another project depends on this project, this 7 | # file won't be loaded nor affect the parent project. For this reason, 8 | # if you want to provide default values for your application for 9 | # 3rd-party users, it should be done in your "mix.exs" file. 10 | 11 | # You can configure for your application as: 12 | # 13 | # config :mogrify_draw, key: :value 14 | # 15 | # And access this configuration in your application as: 16 | # 17 | # Application.get_env(:mogrify_draw, :key) 18 | # 19 | # Or configure a 3rd-party app: 20 | # 21 | # config :logger, level: :info 22 | # 23 | 24 | # It is also possible to import configuration files, relative to this 25 | # directory. For example, you can emulate configuration per environment 26 | # by uncommenting the line below and defining dev.exs, test.exs and such. 27 | # Configuration from the imported file will override the ones defined 28 | # here (which is why it is important to import them last). 29 | # 30 | # import_config "#{Mix.env}.exs" 31 | --------------------------------------------------------------------------------