exmagick v0.0.5 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. Refer to attr/3 for more information
Changes image attributes
Refer to attr/2
Refer to attr/3
Crops the image
Refer to crop/5
Returns the image as a binary. You can change the type of this image
using the :magick attribute
Saves an image to one or multiple files
Refer to image_dump/1
Refer to image_dump/2
Loads an image into the handler. You may provide a file path or a
tuple {:blob, ...} which the second argument is the blob to load
Creates a new image handle with default values
Computes the number of pages of an image
Refer to num_pages/1
Queries the image size
Resizes the image
Refer to size/1
Refer to size/3
Generates a thumbnail for image
Types
Functions
Queries attribute on image. Refer to attr/3 for more information.
In addition to attr/3 the following attributes are defined:
:rowsThe horizontal size in pixels of the image:columnsThe vertical size in pixels of the image
Changes image attributes.
Currently the following attributes are available:
:adjoin(defaults totrue) - set tofalseto produce different images for each frame;:magick- the image type [ex.: PNG]:density- horizontal and vertical resolution in pixels of this image; [default: 72]
Refer to attr/2
Refer to attr/3
Specs
Crops the image.
x,yrefer to starting point, where (0, 0) is top left
Refer to crop/5.
Returns the image as a binary. You can change the type of this image
using the :magick attribute.
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 an image into the handler. You may provide a file path or a
tuple {:blob, ...} which the second argument is the blob to load.
Refer to image_load!/2
Creates a new image handle with default values.
Image attributes may be tuned by using the attr/3 function.
Computes the number of pages of an image.
Queries the image size
Resizes the image.
Refer to size/3
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.