I'm writing an Erlang wrapper for GraphicsMagick, but I'm not sure of which
way to go with the library's syntax.
The first example is more like the gm command itself, where command
arguments are set in one go and the command is run.
The second example is like each command is added to a running queue (stored
in the record created by "gm:new"), where the command is finally processed
and executed by "gm:write".
I was thinking about making the API clean enough so I could support both
methods...
% POSSIBLE SYNTAX 1
gm:convert("/some/image.jpg", "/something/crazy.jpg", [
flip,
magnify,
{rotate, "green", 45},
{blur, 7, 3},
{crop, 300, 300, 150, 130},
{edge, 3}
]).
% Getting width and height of image using Syntax 1 (returns an img_info
record)
Info = gm:identify("/some/image.jpg", [width, height]),
W = Info#img_info.width,
H = Info#img_info.height.
% Cropping an image with Syntax 1
gm:convert("/some/image.jpg", "/something/cropped.jpg", [{crop, 300, 300,
150, 130}]).
% POSSIBLE SYNTAX 2
I1 = gm:new("/some/image.jpg"), % creates the img record
I2 = gm:flip(I1),
I3 = gm:magnify(I2),
I4 = gm:rotate(I3, "green", 45),
I5 = gm:blur(I4, 7, 3),
I6 = gm:crop(I5, 300, 300, 150, 130),
I7 = gm:edge(I6, 3),
gm:write(I7, "/something/crazy.jpg").
% Get width of image using Syntax 2
I8 = gm:identify(I7),
gm:width(I8).
% SYNTAX 2 (Crop an image on one line)
gm:write(gm:crop(gm:new("/some/image.jpg"), 200, 200),
"/something/cropped.jpg").
Any advice?