exmagick v0.0.2 ExMagick
NIF bindings to the GraphicsMagick API.
Examples
Transform a PNG image to JPEG
ExMagick.init!()
|> ExMagick.image_load!(Path.join(__DIR__, "../test/images/elixir.png"))
|> ExMagick.image_dump!("/tmp/elixir.jpg")
Query a file type
ExMagick.init!()
|> ExMagick.image_load!(Path.join(__DIR__, "../test/images/elixir.png"))
|> ExMagick.attr!(:magick)
Generate a thumbnail from an image
ExMagick.init!()
|> ExMagick.image_load!(Path.join(__DIR__, "../test/images/elixir.png"))
|> ExMagick.thumb!(64, 64)
|> ExMagick.image_dump!("/tmp/elixir-thumbnail.jpg")
Generate a thumbnail from an image without breaking errors
with {:ok, handler} <- ExMagick.init(),
img_path = Path.join(__DIR__, "../test/images/elixir.png"),
{:ok, _} <- ExMagick.image_load(handler, img_path),
{:ok, _} <- ExMagick.thumb(handler, 128, 64),
thumb_path = "/tmp/elixir-thumbnail.png",
{:ok, _} <- ExMagick.image_dump(handler, thumb_path),
do: {:ok, thumb_path}
- Converting a multi-page PDF to individual PNG images with 300dpi
ExMagick.init!
|> ExMagick.attr!(:density, "300") # density should be set before loading the image
|> ExMagick.image_load!(Path.joint(__DIR__, "../test/images/elixir.pdf"))
|> ExMagick.attr!(:adjoin, false)
|> ExMagick.image_dump!("/tmp/splitted-page-%0d.png")
Summary
Functions
Queries attribute
on image
Changes image attribute
s
Crops the image
Saves an image to one or multiple files
Loads into the handler an image from a file
Creates a new image handle with default values
Queries the image size
Resizes the image
Generates a thumbnail for image
Types
image
A handle used by the GraphicsMagick API
It’s internal structure should never be assumed, instead, it should be used with this module’s functions
Functions
Specs
attr(image, atom) ::
{:ok, attr_value :: term} |
{:error, reason :: term}
Queries attribute
on image.
In addition to the attributess defined in attr/3
, the following are
available:
:magick
- Image encoding format (e.g. “GIF”);
Changes image attribute
s.
Currently the following attribute
s are available:
:adjoin
(defaults totrue
) - set tofalse
to produce different images for each frame;
Specs
Crops the image.
- x,y refer to starting point, where (0,0) is top left
Saves an image to one or multiple files.
If the attr :adjoin
is false
, multiple files will be created and the
filename is expected to have a printf-formatting sytle (ex.: foo%0d.png
).
Loads into the handler an image from a file.
Specs
init :: {:ok, image} | {:error, reason :: term}
Creates a new image handle with default values.
Image attributes may be tuned by using the attr/2
function.
Specs
size(image) :: {:ok, %{height: pos_integer, width: pos_integer}}
Queries the image size
Resizes the image.
Generates a thumbnail for image.
Note that this method resizes the image as quickly as possible, with more concern for speed than resulting image quality.