Imageflow.Graph (imageflow v0.4.1) View Source
With the Graph API, you can specify a task to process multiple inputs/outputs according to a pipeline of operations.
For example:
alias Imageflow.Graph
Graph.new()
|> Graph.decode_file("input.png") # read input.png
|> Graph.constrain(200, 200) # constrain image to 200x200
|> Graph.saturation(0.5) # set saturation to 0.5 (-1..1 range)
|> Graph.encode_to_file("output.png") # specify output file
|> Graph.run() # run the job ```
Within a Graph
, you specify all the operations, inputs and outputs you
need. Only when Graph.run/1
is called is this actually executed
You can also specify multiple outputs, which is a common use-case. For example, for web/mobile development, you may want to generate multiple images with different resolutions for responsive apps:
alias Imageflow.Graph
Graph.new()
|> Graph.decode_file(@input_path)
|> Graph.branch(fn graph ->
# 2160px wide image for retina displays graph
graph
|> Graph.constrain(2160, nil)
|> Graph.encode_to_file("desktop@2x.png")
end)
|> Graph.branch(fn graph -> # 1080px wide image for desktop
graph
|> Graph.constrain(1080, nil)
|> Graph.encode_to_file("desktop.png")
end)
|> Graph.branch(fn graph -> # 720px wide image for tablet
graph
|> Graph.constrain(720, nil)
|> Graph.encode_to_file("tablet.png")
end)
|> Graph.branch(fn graph -> # 600px wide image for mobile
graph
|> Graph.constrain(600, nil)
|> Graph.encode_to_file("mobile.png")
end)
|> Graph.run()
The above snippet will generate 4 images, all processed under the same
imageflow
job.
Check the documentation to see what other operations are available
You may also want to check the base repo for imageflow
, or its live JSON API documentation
Link to this section Summary
Functions
Creates a new branch, allowing you do add multiple paths and outputs to the graph
Adjusts brightness betweeen -1 and 1
Applies a color filter to the image. All filters will operate on the sRGB color space, so may not provide ideal results.
Constrains image dimensions. By default, it uses the "within" constraint mode from imageflow, but that can be overriden
Adjusts contrast betweeen -1 and 1
Appends a new input file to be decoded
Specifies a destination file for the current branch of the pipeline
Resizes the canvas according to the given amounts for each direction, filling in the empty space with the given HEX color
Draws a of the given color int he given coordinates
Flips the image horizontally
Flips the image vertically
Creates a new graph instance
Like a crop command, but you can specify coordinates outside of the image and thereby add padding. It's like a window.
Rotates image 180 degrees
Rotates image 270 degrees
Rotates image 90 degrees
Adjusts saturation betweeen -1 and 1
Adjusts the alpha channel of the image, from 0 (transparent) to 1 (opaque)
Transposes the image
Link to this section Types
Specs
Specs
Link to this section Functions
Specs
Creates a new branch, allowing you do add multiple paths and outputs to the graph
If you need to output multiple formats, this is what you should use. Perform all common operations first, then call a branch with each specialized part and its corresponding output
Specs
Adjusts brightness betweeen -1 and 1
Specs
Applies a color filter to the image. All filters will operate on the sRGB color space, so may not provide ideal results.
Check the JSON API documentation for available filters.
Specs
Constrains image dimensions. By default, it uses the "within" constraint mode from imageflow, but that can be overriden:
Graph.constrain(graph, 800, 600, %{mode: "fit", gravity: %{percentage:
%{x: 50, y: 50}}
Check the JSON API docs for the constrain operation for more info on all options available
Specs
Adjusts contrast betweeen -1 and 1
Specs
Specs
Appends a new input file to be decoded
Specs
Specifies a destination file for the current branch of the pipeline
No further processing operations should be appended at the current branch after this call.
The last two arguments specify the encoder and optional encoding parameters.
The following parameters are valid encoders:
:jpg
: Alias to:mozjpeg
:jpeg
: Alias to:mozjpeg
:png
: Alias to:lodepng
:webp: Alias to
:webplossless:mozjpeg
:gif
:lodepng
: Lossless PNG:pngquant
: Lossy PNG:webplossy
: Lossy WebP:webplossless
: Lossless WebP
Check the official encoding documentation to see the parameters available to each encoder
expand_canvas(graph, left, top, right, bottom, color_hex \\ "FFFFFF00")
View SourceSpecs
Resizes the canvas according to the given amounts for each direction, filling in the empty space with the given HEX color
Specs
Draws a of the given color int he given coordinates
Specs
Flips the image horizontally
Specs
Flips the image vertically
Specs
new() :: t()
Creates a new graph instance
Specs
Like a crop command, but you can specify coordinates outside of the image and thereby add padding. It's like a window.
Specs
Specs
Rotates image 180 degrees
Specs
Rotates image 270 degrees
Specs
Rotates image 90 degrees
Specs
Adjusts saturation betweeen -1 and 1
Specs
Adjusts the alpha channel of the image, from 0 (transparent) to 1 (opaque)
Specs
Transposes the image