Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying geometry for a composite with mini_magick

I am basically trying to write this command with mini_magick.

gm composite -compose Copy -geometry +0+210 note-transparent1.png note-rugby.png note-rugby-e.png

This is my code:

 image = MiniMagick::Image.open("note-transparent1.png")

result = image.composite(MiniMagick::Image.open("note-rugby.png") do |c|
  c.compose = "Copy"
  c.geometry = "+0+210"
end)
result.write "note-rugby-e.png"

The images are composited and written to the new file; however the geometry isn't respected. The image is not offset.

I also tried setting the mini_magick processor to ImageMagick instead of GraphicsMagick, but I get the same result.

Any ideas?

like image 650
rmw Avatar asked Apr 13 '11 18:04

rmw


2 Answers

I am using mini_magick with ImageMagick, and the below code works for compositing.

bground = MiniMagick::Image.open("bground.jpg")
image = MiniMagick::Image.open("image.jpg")

result = bground.composite(image) do |c|
  c.gravity "NorthWest"
  c.geometry '400x400+20+56' 
end

result.write "output.jpg"
like image 123
Rhb123 Avatar answered Sep 28 '22 00:09

Rhb123


According to rubydoc minimagic

first_image = MiniMagick::Image.open "first.jpg"
second_image = MiniMagick::Image.open "second.jpg"

result = first_image.composite(second_image) do |c|
 c.compose "Over" # OverCompositeOp
 c.geometry "+20+20" # copy second_image onto first_image from (20, 20)
end
result.write "output.jpg"
like image 38
Arvind singh Avatar answered Sep 28 '22 01:09

Arvind singh