Gi (Gi v0.1.1) View Source

Manipulating Graphics Interfacing

Link to this section Summary

Functions

Get information of image.

Mogrify image with option.

Opens image source, raises a File.Error exception in case of failure.

Link to this section Functions

Specs

gm_identify(Gi.Image.t()) :: Gi.Image.t()

Get information of image.

Example

iex>  Gi.open("test/example.jpg")
...>  |> Gi.gm_identify
%Gi.Image{
  animated: false,
  dirty: %{},
  ext: ".jpg",
  format: "JPEG (Joint Photographic Experts Group JFIF format)",
  frame_count: 1,
  height: 312,
  list_command: [],
  path: "test/example.jpg",
  width: 820
}

Specs

gm_mogrify(Gi.Image.t(), Keyword.t()) :: Gi.Image.t()

Mogrify image with option.

Options

  • :resize - Resize image to value "WxH" or "WxH!".
    • "WxH" keep ratio of the original image.
      • Example: "400x300", "150x100" ...
    • "WxH!" exact size.
      • Example: "300x200!", "200x100!" ...
  • :format - Format image to value as jpg, png, webp...
  • :draw - Draw object on image:
    • "text x,y string" - draw string at position x,y.
      • Example: "text 150,150 'Theta.vn'"
    • "image Over x,y,w,h file" - draw file on image at position x,y with width w va height h.
      • Example: "image Over 0,0,400,600 d/logo.png"
  • :pointsize - pointsize of the PostScript, X11, or TrueType font for text, value as integer.

Example

# Resize image to width x height with ratio (WxH)
iex>  Gi.open("test/example.jpg")
...>  |> Gi.gm_mogrify(resize: "200x100")
...>  |> Gi.save(path: "test/example_resize.jpg")

iex>  Gi.open("test/example_resize.jpg")
...>  |> Gi.gm_identify
%Gi.Image{
  animated: false,
  dirty: %{},
  ext: ".jpg",
  format: "JPEG (Joint Photographic Experts Group JFIF format)",
  frame_count: 1,
  height: 76,
  list_command: [],
  path: "test/example_resize.jpg",
  width: 200
}

# Resize image to width x height (WxH!)
Gi.open("example.jpg") # example.jpg (300x200)
|> Gi.gm_mogrify(resize: "200x100!")
|> Gi.save() # => example.jpg (200x100)

# Format image to jpg, png, webp, ...
Gi.open("example.jpg")
|> Gi.gm_mogrify(format: "webp")
|> Gi.save() # => create new file "example.webp"

# Draw text on image "text x,y string"
Gi.open("example.jpg")
|> Gi.gm_mogrify(draw: "text 150,150 'Lang Pham'")
|> Gi.save()

# Draw text on image "text x,y string" with pointsize,
Gi.open("example.jpg")
|> Gi.gm_mogrify([pointsize: 30, draw: "text 150,150 'Lang Pham'"])
|> Gi.save()

# Draw image on image "image Over x,y,w,h file"
Gi.open("example.jpg")
|> Gi.gm_mogrify(draw: "image Over 100,100,200, 200 dir/logo.a")
|> Gi.save()

# Multi utilities
Gi.open("example.jpg")
|> Gi.gm_mogrify([resize: "300x200", draw: "text 150,150 'Theta.vn'"])
|> Gi.save()

Specs

open(binary()) :: Gi.Image.t()

Opens image source, raises a File.Error exception in case of failure.

Parameters

  • path: path to file image.

Example

iex>  Gi.open("test/example.jpg")
%Gi.Image{
  animated: false,
  dirty: %{},
  ext: ".jpg",
  format: nil,
  frame_count: 1,
  height: nil,
  list_command: [],
  path: "test/example.jpg",
  width: nil
}

Specs

save(Gi.Image.t(), Keyword.t()) :: Gi.Image.t()

Save image.

Options

  • :path - Value as path. Save as image to path

Example

iex>  Gi.open("test/example.jpg")
...>  |> Gi.save()
%Gi.Image{
  animated: false,
  dirty: %{},
  ext: ".jpg",
  format: nil,
  frame_count: 1,
  height: nil,
  list_command: [],
  path: "test/example.jpg",
  width: nil
}

iex>  Gi.open("test/example.jpg")
...>  |> Gi.save(path: "test/new_example.jpg")
%Gi.Image{
  animated: false,
  dirty: %{},
  ext: ".jpg",
  format: nil,
  frame_count: 1,
  height: nil,
  list_command: [],
  path: "test/new_example.jpg",
  width: nil
}