Reputation: 27517
I want to combine two images (one background image, one text image) into one big image.
I believe I have the background image done since it's just based off a file. However, I'm having trouble trying to create an image from scratch. Any tips?
image = MiniMagick::Image.open("public/text_response_bg.png")
image.combine_options do |i|
i.size "1024x512"
end
text = MiniMagick::Image.new #<-- does not work
text.combine_options do |i|
i.size "700x200"
i.gravity 'center'
i.fill 'white'
i.caption 'blahblahblah'
end
result = image.composite(text) do |c|
c.compose "Over"
c.geometry "+20+20"
end
Upvotes: 1
Views: 3502
Reputation: 533
Create an image from scratch with the following Ruby Code:
MiniMagick::Tool::Convert.new do |i|
i.size "700x200"
i.gravity "center"
i.xc "white"
i.caption "blablabla"
i << "test_image.jpg"
end
Upvotes: 9
Reputation: 888
MiniMagick provide a method MiniMagick::Image.create
to create a new image but seems not work with this issues
Use ImageMagick primary command you can create a pure color image like
convert -size 800x600 xc:"#ffffff" write.jpg
So if not mind using system command to create image you can do:
cmd = "convert -size 800x600 xc:'#ffffff' WRITE_IMAGE.jpg"
system(cmd)
UPDATE: I use MiniMagick 3.8.0, and see latest version 4.0.1 has a MiniMagick::Shell
class, think it could run that custom ImageMagick command directly.
Upvotes: 2