项目作者: route

项目描述 :
Image processing in Elixir (ImageMagick command line wrapper)
高级语言: Elixir
项目地址: git://github.com/route/mogrify.git
创建时间: 2014-09-30T14:19:59Z
项目社区:https://github.com/route/mogrify

开源协议:MIT License

下载


Mogrify

Build Status
Module Version
Hex Docs
Total Download
License
Last Updated

An Elixir wrapper for ImageMagick command line.

Documentation: https://hexdocs.pm/mogrify/

Requirements

You must have ImageMagick installed of course.

Installation

Add this to your mix.exs file, then run mix do deps.get, deps.compile:

  1. def deps do
  2. {:mogrify, "~> 0.9.3"}
  3. end

Configuration

Configure the ImageMagick executable paths (optional):

Configure mogrify command:

  1. config :mogrify, mogrify_command: [
  2. path: "magick",
  3. args: ["mogrify"]
  4. ]

Configure convert command:

  1. config :mogrify, convert_command: [
  2. path: "magick",
  3. args: ["convert"]
  4. ]

Configure identify command:

  1. config :mogrify, identify_command: [
  2. path: "magick",
  3. args: ["identify"]
  4. ]

Examples

Thumbnailing:

  1. import Mogrify
  2. # This does operations on an original image:
  3. open("input.jpg") |> resize("100x100") |> save(in_place: true)
  4. # save/1 creates a copy of the file by default:
  5. image = open("input.jpg") |> resize("100x100") |> save
  6. IO.inspect(image) # => %Image{path: "/tmp/260199-input.jpg", ext: ".jpg", ...}
  7. # Resize to fill
  8. open("input.jpg") |> resize_to_fill("450x300") |> save
  9. # Resize to limit
  10. open("input.jpg") |> resize_to_limit("200x200") |> save
  11. # Extent
  12. open("input.jpg") |> extent("500x500") |> save
  13. # Gravity
  14. open("input.jpg") |> gravity("Center") |> save

Converting:

  1. import Mogrify
  2. image = open("input.jpg") |> format("png") |> save
  3. IO.inspect(image) # => %Image{path: "/tmp/568550-input.png", ext: ".png", format: "png"}

Getting info:

  1. import Mogrify
  2. image = open("input.jpg") |> verbose
  3. IO.inspect(image) # => %Image{path: "input.jpg", ext: ".jpg", format: "jpeg", height: 292, width: 300}

Getting reduced info in a “lighter” way (uses less memory):

  1. import Mogrify
  2. info = identify("input.jpg")
  3. IO.inspect(info) # => %{format: "jpeg", height: 292, width: 300}

Using custom commands to create an image with markup:

  1. import Mogrify
  2. %Mogrify.Image{path: "test.png", ext: "png"}
  3. |> custom("size", "280x280")
  4. |> custom("background", "#000000")
  5. |> custom("gravity", "center")
  6. |> custom("fill", "white")
  7. |> custom("font", "DejaVu-Sans-Mono-Bold")
  8. |> custom("pango", ~S(<span foreground="yellow">hello markup world</span>))
  9. |> create(path: ".")

Plasma backgrounds:

  1. import Mogrify
  2. %Mogrify.Image{path: "test.png", ext: "png"}
  3. |> custom("size", "280x280")
  4. |> custom("seed", 10)
  5. |> custom("plasma", "fractal")

Creating new images: See mogrify_draw for an example of generating a new image from scratch.

Changelog

See the changelog for important release notes between Mogrify versions.

Copyright (c) 2014 Dmitry Vorotilin

Mogrify source code is licensed under the MIT License.