Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magick composite image gravity #58

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions magick/wand/image.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,32 @@ do
}
return unpack(res)
end,
composite = function(self, blob, x, y, op)
composite = function(self, blob, x, y, op, clip_to_self)
if op == nil then
op = "OverCompositeOp"
end
if clip_to_self == nil then
clip_to_self = true
end
if type(blob) == "table" and blob.__class == Image then
blob = blob.wand
end
op = assert(composite_operators:to_int(op), "invalid operator type")
return handle_result(self, lib.MagickCompositeImage(self.wand, blob, op, x, y))
return handle_result(self, lib.MagickCompositeImage(self.wand, blob, op, clip_to_self, x, y))
end,
composite_gravity = function(self, blob, op, gtype)
if op == nil then
op = "OverCompositeOp"
end
if gtype == nil then
gtype = "NorthWestGravity"
end
if type(blob) == "table" and blob.__class == Image then
blob = blob.wand
end
op = assert(composite_operators:to_int(op), "invalid operator type")
gtype = assert(gravity:to_int(gtype), "invalid gravity type")
return handle_result(self, lib.MagickCompositeImageGravity(self.wand, blob, op, gtype))
end,
get_blob = function(self)
local len = ffi.new("size_t[1]", 0)
Expand Down
14 changes: 12 additions & 2 deletions magick/wand/image.moon
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,23 @@ class Image extends require "magick.base_image"
res = { handle_result @, lib.MagickRotateImage @wand, pixel, degrees }
unpack res

composite: (blob, x, y, op="OverCompositeOp") =>
composite: (blob, x, y, op="OverCompositeOp", clip_to_self=true) =>
if type(blob) == "table" and blob.__class == Image
blob = blob.wand

op = assert composite_operators\to_int(op), "invalid operator type"
handle_result @,
lib.MagickCompositeImage @wand, blob, op, x, y
lib.MagickCompositeImage @wand, blob, op, clip_to_self, x, y

composite_gravity: (blob, op="OverCompositeOp", gtype="NorthWestGravity") =>
if type(blob) == "table" and blob.__class == Image
blob = blob.wand

op = assert composite_operators\to_int(op), "invalid operator type"
gtype = assert gravity\to_int(gtype), "invalid gravity type"

handle_result @,
lib.MagickCompositeImageGravity @wand, blob, op, gtype

get_blob: =>
len = ffi.new "size_t[1]", 0
Expand Down
5 changes: 5 additions & 0 deletions magick/wand/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@ ffi.cdef([[ typedef void MagickWand;

MagickBooleanType MagickCompositeImage(MagickWand *wand,
const MagickWand *source_wand,const CompositeOperator compose,
const MagickBooleanType clip_to_self,
const ssize_t x,const ssize_t y);

MagickBooleanType MagickCompositeImageGravity(MagickWand *wand,
const MagickWand *source_wand,const CompositeOperator compose,
const GravityType gravity);

GravityType MagickGetImageGravity(MagickWand *wand);
MagickBooleanType MagickSetImageGravity(MagickWand *wand,
const GravityType gravity);
Expand Down
5 changes: 5 additions & 0 deletions magick/wand/lib.moon
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ ffi.cdef [[

MagickBooleanType MagickCompositeImage(MagickWand *wand,
const MagickWand *source_wand,const CompositeOperator compose,
const MagickBooleanType clip_to_self,
const ssize_t x,const ssize_t y);

MagickBooleanType MagickCompositeImageGravity(MagickWand *wand,
const MagickWand *source_wand,const CompositeOperator compose,
const GravityType gravity);

GravityType MagickGetImageGravity(MagickWand *wand);
MagickBooleanType MagickSetImageGravity(MagickWand *wand,
const GravityType gravity);
Expand Down