gmex v0.1.7 Gmex

A simple wrapper for GraphicsMagick in Elixir.

Link to this section Summary

Functions

Returns a keywords list with information about the image like width, height, size, format and quality.

Opens image source.

Apply a GraphicsMagick option to the given image.

Apply a list GraphicsMagick option to the given image.

Saves the modified image

Link to this section Types

Link to this type

gmex_error()

gmex_error() :: {:error, any()}
Link to this type

image()

image() :: {:ok, %Gmex.Image{image: term(), options: term()}}
Link to this type

image_info()

image_info() :: [
  width: Integer.t(),
  height: Integer.t(),
  size: String.t(),
  format: String.t(),
  quality: Integer.t()
]
Link to this type

open_options()

open_options() :: [{:gm_path, String.t()}]
Link to this type

option()

option() ::
  [{:adjoin, boolean()}]
  | [{:blur, {option_param(), option_param()}}]
  | [{:blur, option_param()}]
  | [{:crop, {option_param(), option_param(), option_param(), option_param()}}]
  | [{:crop, {option_param(), option_param()}}]
  | [{:edge, option_param()}]
  | [
      {:extent,
       {option_param(), option_param(), option_param(), option_param()}}
    ]
  | [{:extent, {option_param(), option_param()}}]
  | [{:flatten, boolean()}]
  | [{:fill, String.t()}]
  | [{:strip, boolean()}]
  | [{:format, String.t()}]
  | [{:gravity, String.t()}]
  | [{:magnify, boolean()}]
  | [{:matte, boolean()}]
  | [{:negate, true}]
  | [{:opaque, String.t()}]
  | [{:quality, Integer.t()}]
  | [{:resize, {option_param(), option_param()}}]
  | [{:resize, Integer.t()}]
  | [{:rotate, Integer.t()}]
  | [{:size, {option_param(), option_param()}}]
  | [{:size, {option_param(), option_param(), option_param()}}]
  | [{:thumbnail, {:thumbnail, option_param(), option_param()}}]
  | [{:thumbnail, {:thumbnail, option_param()}}]
  | [{:transparent, String.t()}]
  | [{:type, String.t()}]
  | [{:custom, [option_param()]}]
Link to this type

option_param()

option_param() :: String.t() | Integer.t() | Float.t()
Link to this type

resize_options()

resize_options() :: [
  width: Integer.t(),
  height: Integer.t(),
  type: :fill | :fit
]

Link to this section Functions

Link to this function

get_info(image)

get_info(image()) :: {:ok, image_info()} | gmex_error()

Returns a keywords list with information about the image like width, height, size, format and quality.

Link to this function

open(src_path, options \\ [])

open(String.t(), [open_options()]) :: image() | gmex_error()

Opens image source.

Options

  • :gm_path - path to GraphicsMagick executable, defaults to gm, if the executable is missing an error will be returned.

Example

iex> Gmex.open( "test/images/blossom.jpg" )
{ :ok, %Gmex.Image{ image: "test/images/blossom.jpg", options: [ "gm" ] } }

iex> Gmex.open( "test/images/blossom.jpg", gm_path: "/404/gm" )
{ :error, "graphicsmagick executable not found at:/404/gm" }

iex> Gmex.open( "non-existing.png" )
{ :error, :enoent }
Link to this function

option(arg, arg2)

option(image(), option()) :: image()

Apply a GraphicsMagick option to the given image.

Example

iex> Gmex.open( "test/images/blossom.jpg" )
iex> |> Gmex.option( negate: true )
iex> |> Gmex.option( resize: { 50, 50 } )
iex> |> Gmex.option( strip: true )
iex> |> Gmex.option( format: "jpg" )
{ :ok, %Gmex.Image{ image: "test/images/blossom.jpg", options: [ "gm", "-negate", "-resize", "50x50", "-strip", "-format", "jpg" ] } }

List of available options:

OptionGraphicsMagick
adjoin: true+adjoin
adjoin: false-adjoin
blur: { radius, sigma }-blur radiusxsigma
blur: radius-blur radius
crop: { width, height, x_offset, y_offset }-crop widthxheight+x_offset+y_offset
crop: { width, height }-crop widthxheight
edge: edge-edge edge
extent: { width, height, x_offset, y_offset }-extent widthxheight+x_offset+y_offset
extent: { width, height }-extent widthxheight
flatten: true-flatten
fill: color-fill color
strip: true-strip
flip: true-flip
format: format }-format format
gravity: gravity-gravity gravity
magnify: true-magnify
matte: true+matte
matte: false-matte
negate: true-negate
opaque: color-opaque color
quality: quality-quality quality
resize: { width, height }-resize widthxheight
resize: percents-resize percents%
rotate: degrees-rotate degrees
size: { width, height }-size widthxheight
size: { width, height, offset }-size widthxheight+offset
thumbnail: { :thumbnail, width, height }-thumbnail widthxheight
thumbnail: { :thumbnail, percents }-thumbnail percents%
transparent: color-transparent color
type: type-type type
custom: [ arg1, arg2, arg3... ]arg1 arg2 arg3 ...
Link to this function

options(arg, list)

options(image(), option()) :: image() | gmex_error()

Apply a list GraphicsMagick option to the given image.

Example

iex> Gmex.open( "test/images/blossom.jpg" )
iex> |> Gmex.options( negate: true, resize: { 50, 50 }, strip: true, format: "jpg" )
{ :ok, %Gmex.Image{ image: "test/images/blossom.jpg", options: [ "gm", "-negate", "-resize", "50x50", "-strip", "-format", "jpg" ] } }
Link to this function

resize(image, options \\ [])

resize(image(), resize_options()) :: image() | gmex_error()

Resizes image

Options

  • :width - (Optional) width of the resized image, if not specified will be calculated based on proportions.
  • :height - (Optional) height of the resized image, if not specified will be calculated based on proportions.
  • :type - (Optional) resize type, can be either :fill or :fit, defaults to :fill.

    • :fill - Generates images of the specified size with cropping.
    • :fit - Generates an image that will fit in the specified size, no cropping.

Example

iex> Gmex.open( "test/images/blossom.jpg" )
iex> |> Gmex.resize( width: 300, height: 200, type: :fill )
iex> |> Gmex.save( "newimage.jpg" )
{ :ok, nil }
Link to this function

save(image, dest_path)

save(image(), String.t()) :: image() | gmex_error()

Saves the modified image

Example

iex> Gmex.open( "test/images/blossom.jpg" )
iex> |> Gmex.save( "newimage.jpg" )
{ :ok, nil }