Gi (Gi v0.1.0) 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("example.jpg")
 iex> |> Gi.gm_identify
 %Gi.Image{
         animated: false,
         dirty: %{},
         ext: ".jpg",
         format: "JPEG (Joint Photographic Experts Group JFIF format)",
         frame_count: 1,
         height: 400,
         list_command: [],
         path: "example.jpg",
         width: 300
        }

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)
Gi.open("example.jpg") # example.jpg (300x200)
|> Gi.gm_mogrify(resize: "200x100")
|> Gi.save() # => example.jpg (150x100)

# 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

  • string_path: path to file image.

Example

 iex>  Gi.open("example.jpg")
 %Gi.Image{
         animated: false,
         dirty: %{},
         ext: ".jpg",
         format: nil,
         frame_count: 1,
         height: nil,
         list_command: [],
         path: "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

Gi.open("example.jpg")
|> Gi.save()

Gi.open("example.jpg")
|> Gi.save(path: "new_example.jpg")